-1

I am working on Cross validation for k-fold using ridge regression. I want to do y_pred using ridge_regression_sklearn and got the error message that 'ridge_regression_sklearn' is not defined.

Some can please help me how to fix it. I didn't found the right import for it. May be that is the problem???

NameError                                 Traceback (most recent call last)
<ipython-input-131-34a4b717d52b> in <module>
      1 alphas = np.logspace(-7,7,100)
----> 2 mse_cv = ridgeCV(X_train, y_train, n_folds=10, alphas=alphas)

<ipython-input-130-fea3c1471177> in ridgeCV(X, y, n_folds, alphas)
     33         for k in range(len(alphas)):
---> 35             weights, y_pred = ridge_regression_sklearn(test_X, training_X, training_y, alphas[k])
     36             cv_results_mse[i][k] = mean_squared_error(test_y, y_pred)
     37 

NameError: name 'ridge_regression_sklearn' is not defined

I have the following imports for the project i am working

%matplotlib notebook

%matplotlib inline

import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import numpy as np from scipy.io import loadmat from scipy import stats import copy import pylab from sklearn import linear_model from sklearn.metrics import mean_squared_error, r2_score from sklearn.linear_model import LinearRegression

  • Include a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) in your questions, please. – Amitai Irron May 18 '20 at 16:28

1 Answers1

0

Most likely something like this would be from ridge_regression_sklearn not being imported. Can you show us how you did import it.

smal
  • 177
  • 10
  • # %matplotlib notebook %matplotlib inline import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import numpy as np from scipy.io import loadmat from scipy import stats import copy import pylab from sklearn import linear_model from sklearn.metrics import mean_squared_error, r2_score from sklearn.linear_model import LinearRegression – Atif Saeed May 18 '20 at 16:04
  • I think i have not added the right import actually i didn't found can you please help me how to find the import for this one – Atif Saeed May 18 '20 at 16:05
  • Do you mean to do linear_model.ridge_regression? – smal May 18 '20 at 16:06
  • If that worked please accept my answer. I am trying to get to 50 rep. – smal May 18 '20 at 16:17
  • I tried this: from sklearn.linear_model import ridge_regression but this is also not working – Atif Saeed May 18 '20 at 16:22
  • I have pip 20.0.2 installed it mean first i need to install pip 30 you mean – Atif Saeed May 18 '20 at 16:34
  • No the pip is fine try to do either pip3 freeze. If that fails do pip freeze. Put the output here. – smal May 18 '20 at 16:36
  • I update it to 20.1 which is the latest version i don't know about pip3 – Atif Saeed May 18 '20 at 16:37
  • Could you give us the result of pip freeze. – smal May 20 '20 at 20:59