训练线性回归

时间:2017-09-20 18:24:19

标签: python-3.x

我正在尝试在python中运行渐变下降算法。当我将数据拆分成列时,我得到了算法。 X是特征(独立),y是目标。我想修改我的代码,以便它接受训练数据(X_train,y_train,X_test,y_test)。我不知道如何做到这一点。

def grad(theta,alpha,X,y):

theta1 = np.matrix(np.zeros(theta.shape))
hypothesis = (X * theta.T)
error = hypothesis - y
for j in range(theta.shape[1]):
    temp = np.multiply(error, X[:,j])
    theta1[0,j] = theta[0,j] - ((alpha / len(X)) * np.sum(temp))

return theta1

gradientDecentMatP(theta,alpha,X,y)

0 个答案:

没有答案