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