使用梯度下降的线性回归

时间:2019-09-13 04:53:43

标签: python-3.x machine-learning linear-regression gradient-descent

实施梯度下降后获得负的负无穷大值

def derivative(w,w0,X,alpha,y):
    j_wi = 0
    j_w0 = 0
    for j in range(0,100):
        for i in range(0,X.shape[0]):
            j_wi += (y[i] - (np.sum((w*X[i]) + w0, axis =0))) * (-X[i])
            j_w0 += -(y[i] - (np.sum(w * X[i] + w0)))
        j_wi = 2*j_wi/X.shape[0]
        j_w0 = 2*j_w0/X.shape[0]
    w = w-(alpha*j_wi)
    w0 = w0-(alpha*j_w0)
    return w, w0

0 个答案:

没有答案