具有随机梯度下降算法的回归

问题描述 投票:0回答:1

[我正在使用《机器学习在行动》中研究回归,并且看到了如下所示的来源:

def stocGradAscent0(dataMatrix, classLabels):
    m, n = np.shape(dataMatrix)
    alpha = 0.01
    weights = np.ones(n)   #initialize to all ones
    for i in range(m):
        h = sigmoid(sum(dataMatrix[i]*weights))
        error = classLabels[i] - h
        weights = weights + alpha * error * dataMatrix[i]
    return weights

您可能会猜出代码的含义。但是我不明白。我读过几次书,并搜索了相关的资料,例如Wiki或google,其中指数函数是从中获得最小差异的权重。为什么我们使用指数函数和X *权重之和来获得适当的权重?这将是一种OLS。无论如何,我们得到如下结果:enter image description here

谢谢!

machine-learning regression linear-regression exponential stochastic-gradient
1个回答
0
投票

这只是线性回归的基础。在for循环中,它尝试计算错误函数

Z =β₀+β₁X;其中β₁和X是矩阵

hΘ​​(x)= S形(Z)

即hΘ(x)= 1 /(1 + e ^-(β₀+β₁X)

然后更新权重。通常,最好在for循环中给它较大的迭代次数,例如1000,如果我猜它很小的话。

我想解释更多,但我不能比这个家伙here更好地解释>

学习愉快!

© www.soinside.com 2019 - 2024. All rights reserved.