无法对测试数据进行预测

Unable to make Prediction on Test Data

#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'

使用其他变量名代替 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)