无法对测试数据进行预测

时间:2020-05-13 05:59:47

标签: python scikit-learn linear-regression sklearn-pandas

#Linear Regression Model
from sklearn import linear_model
linear_model = linear_model.LinearRegression()
linear_model.fit(x_train, y_train)
print("Linear Model Coefficients:", linear_model.coef_)
print("Linear Model Intercepts:", linear_model.intercept_)
print("")
#Predicting Prices using the models
y_pred = linear_model.predict(x_test)

但这给出了输出:模块'sklearn.linear_model'没有属性'predict'

1 个答案:

答案 0 :(得分:0)

使用其他变量名代替linear_model。变量和函数名称相等,导致出现错误。

示例代码如下。

from sklearn import linear_model
model = linear_model.LinearRegression()
model.fit(x_train, y_train)
print("Linear Model Coefficients:", model.coef_)
print("Linear Model Intercepts:", model.intercept_)
print("")
#Predicting Prices using the models
y_pred = model.predict(x_test)