小编Def*_*ure的帖子

为什么简单的梯度下降会发散?

这是我在一个变量中实现梯度下降的第二次尝试,但它总是发散。有任何想法吗?

这是一种简单的线性回归,用于最小化一个变量的残差平方和。

def gradient_descent_wtf(xvalues, yvalues):
    tolerance = 0.1

    #y=mx+b
    #some line to predict y values from x values
    m=1.
    b=1.

    #a predicted y-value has value mx + b

    for i in range(0,10):

        #calculate y-value predictions for all x-values
        predicted_yvalues = list()
        for x in xvalues:
            predicted_yvalues.append(m*x + b)

        # predicted_yvalues holds the predicted y-values

        #now calculate the residuals = y-value - predicted y-value for each point
        residuals = list()
        number_of_points = len(yvalues)
        for n in range(0,number_of_points):
            residuals.append(yvalues[n] - predicted_yvalues[n])

        ## …
Run Code Online (Sandbox Code Playgroud)

python gradient regression

5
推荐指数
1
解决办法
607
查看次数

标签 统计

gradient ×1

python ×1

regression ×1