Python 3:NameError:未定义名称'sklearn'

时间:2017-04-25 11:05:17

标签: python scikit-learn regression

我正在尝试运行弹性网络回归,但得到以下错误:NameError:名称'sklearn'未定义...非常感谢任何帮助!

enter image description here

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

1 个答案:

答案 0 :(得分:3)

导入linear_model

更改

ElasticNet = sklearn.linear_model.ElasticNet()

ElasticNet = linear_model.ElasticNet()