无法对测试数据进行预测。

问题描述 投票:0回答:1
#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'。

python scikit-learn linear-regression sklearn-pandas
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.