lr = 0.1
n_iterations = 1000
m = 5
theta = np.array([[1000],[989],[123],[3455]])
for iterations in n_iterations:
gradients = 2/m * X_b.T.dot(X_b.dot(theta) - y)
theta = theta - lr * gradients
theta在执行代码后,它显示错误'int‘不可迭代。
更多数据:
X_b = np.asanyarray(df[['area', 'bedrooms', 'age']])从csv文件
我使用三个参数(面积,卧室,年龄)来预测价格,即
请帮我纠正那个错误
发布于 2020-11-23 16:29:12
n_iterations是一个整数,它不像错误所说的那样是可迭代的。我认为你想要循环n_iterations次。
尝试使用range,如下所示:
lr = 0.1
n_iterations = 1000
m = 5
theta = np.array([[1000],[989],[123],[3455]])
for iterations in range(n_iterations):
gradients = 2/m * X_b.T.dot(X_b.dot(theta) - y)
theta = theta - lr * gradients
thetahttps://stackoverflow.com/questions/64964833
复制相似问题