【发布时间】:2021-01-24 00:43:12
【问题描述】:
我正在使用 MSE 来衡量损失。在下面的代码中,我实现了 loss_mse 函数,该函数应该使用给定的 theta 计算输入集的 MSE
def loss_mse(X,y,theta):
length = len(y)
predictions = X.dot(theta)
error = (1/2*length) * np.sum(np.square(predictions - y))
return error
为了测试上述功能,我编写了以下测试用例:
X = np.array([[2.0, 1.0, 3.0], [3.0, 6.0, 2.0]])
y = np.array([1.0, 1.0])
theta = np.array([[1.0], [2.0],[1.0]])
error = loss_mse(X, y, theta)
print(error)
我必须得到73 的答案,但我得到的是584。我不明白我在哪里做错了。
【问题讨论】:
标签: python python-3.x machine-learning data-science naivebayes