Invalid parameter for sklearn estimator Ridge() and Lasso()

977 views Asked by At

I am implementing an example from a tutorial, using Python 3.6.5 and scikit-learn 0.23.2

from sklearn.model_selection import GridSearchCV 
from sklearn.linear_model import Ridge

ridge = Ridge()

r_parameters = {'ridge__alpha:':[1e-15, 1e-10, 1e-8, 1e-4, 1e-3, 1e-2, 1, 5, 10, 20]}

ridge_regressor = GridSearchCV(ridge, r_parameters, scoring = 'neg_mean_squared_error', cv = 5)

ridge_regressor.fit(X, y)

The error being returned boils down to:

ValueError: Invalid parameter ridge for estimator Ridge(). Check the list of available parameters with `estimator.get_params().keys()`.

The same problem when I am doing it for Lasso

from sklearn.linear_model import Lasso

lasso = Lasso(tol=0.05)
l_parameters = {'lasso__alpha:':[1e-15, 1e-10, 1e-8, 1e-4, 1e-3, 1e-2, 1, 5, 10, 20]}

lasso_regressor = GridSearchCV(lasso, l_parameters, scoring = 'neg_mean_squared_error', cv = 5)

lasso_regressor.fit(X, y)

Similar error for lasso as seen below:

ValueError: Invalid parameter lasso for estimator Lasso(tol=0.05). Check the list of available parameters with `estimator.get_params().keys()`.

What is causing this error?

1

There are 1 answers

0
sentence On

As suggested by @SergeyBushmanov, you should use alpha as parameter, see here for Ridge() and here for Lasso().

Moreover, note that you wrote the colon inside the quote. That is a typo.

To sum up:

r_parameters = {'alpha':[1e-15, 1e-10, 1e-8, 1e-4, 1e-3, 1e-2, 1, 5, 10, 20]}

and

l_parameters = {'alpha':[1e-15, 1e-10, 1e-8, 1e-4, 1e-3, 1e-2, 1, 5, 10, 20]}