【发布时间】:2020-07-01 14:58:46
【问题描述】:
这是一个简单的代码,所以我遗漏了一些很明显的东西:
print(X.dtype)
print(y.dtype)
lin_reg = LinearRegression()
lin_reg.fit(X, y)
print("Score: " + str(lin_reg.score(X,y)))
print("Coefs: " + str(lin_reg.coef_))
print("Intercept: " + str(lin_reg.intercept_))
输出是:
float64
int64
Score: 0.8725949819648744
Coefs: [[825.09663073]]
Intercept: [-122.41197463]
现在,问题是当我尝试预测时。首先我得到一个样本:
x_sample = X[:144]
y_sample = y[:144]
print("Predictions: " + lin_reg.predict(x_sample))
这给了我这个我不明白的错误:
---------------------------------------------------------------------------
UFuncTypeError Traceback (most recent call last)
<ipython-input-791-1d189ee47b31> in <module>
2 y_sample = y[:144]
3
----> 4 print("Predictions: " + lin_reg.predict(x_sample))
UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')
【问题讨论】:
标签: python-3.x scikit-learn linear-regression