这是一个简单的代码,所以我缺少一些显而易见的东西:
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')
好,我明白了!
问题与数组无关。在打印方法中:
print("Predictions: " + str(lin_reg.predict(x_sample)))