我正在尝试运行弹性网络回归,但得到以下错误:NameError:名称'sklearn'未定义...非常感谢任何帮助!
# ElasticNet Regression
from sklearn import linear_model
import statsmodels.api as sm
ElasticNet = sklearn.linear_model.ElasticNet() # create a lasso instance
ElasticNet.fit(X_train, y_train) # fit data
# print(lasso.coef_)
# print (lasso.intercept_) # print out the coefficients
print ("R^2 for training set:"),
print (ElasticNet.score(X_train, y_train))
print ('-'*50)
print ("R^2 for test set:"),
print (ElasticNet.score(X_test, y_test))
答案 0 :(得分:3)
导入linear_model
更改
ElasticNet = sklearn.linear_model.ElasticNet()
到
ElasticNet = linear_model.ElasticNet()