4

I am trying to run an Elastic Net regression but get the following error: NameError: name 'sklearn' is not defined... any help is greatly appreciated!

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
  • 2
    Use linear_model.ElasticNet(). Drop sklearn Commented Apr 25, 2017 at 11:07

1 Answer 1

7

As you have imported linear_model

Change

ElasticNet = sklearn.linear_model.ElasticNet()

to

ElasticNet = linear_model.ElasticNet()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.