Reputation: 1987
I am getting the following error for the below code, but cannot figure out why my parameter is invalid. SelectFromModel
is a valid input in a Pipeline as it has a fit and transform function.
ValueError: Invalid parameter sfm_threshold for estimator Pipeline.
Check the list of available parameters with
`estimator.get_params().keys()`
from sklearn.preprocessing import PolynomialFeatures, StandardScaler
from sklearn.linear_model import LassoCV, LinearRegression
from sklearn.feature_selection import SelectFromModel
from sklearn.pipeline import Pipeline
poly = PolynomialFeatures()
std = StandardScaler()
ls = LassoCV(cv=10)
sfm = SelectFromModel(estimator=ls)
lr = LinearRegression()
pipe_lr = Pipeline([('poly', poly),
('std', std),
('sfm', sfm),
('lr', lr)])
param_range_degree = [2, 3]
param_range_threshold = [0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5]
param_grid_lr = [{'poly__degree': param_range_degree,
'sfm__threshold': param_range_threshold}]
When I run pipe_lr.get_params().keys()
I get the following output, which does in fact include sfm__threshold
, which I copy and pasted exactly as is.
['std__with_mean',
'sfm__estimator__precompute',
'lr__n_jobs',
'sfm__prefit',
'poly',
'sfm__threshold',
'sfm__estimator__cv',
'sfm__estimator__max_iter',
'sfm__estimator__positive',
'sfm__estimator__n_alphas',
'std__with_std',
'sfm__estimator__random_state',
'std__copy',
'lr__normalize',
'sfm__estimator__copy_X',
'lr',
'sfm__estimator__n_jobs',
'poly__interaction_only',
'sfm__estimator__fit_intercept',
'sfm__estimator__tol',
'sfm__estimator',
'sfm__estimator__verbose',
'sfm',
'sfm__estimator__normalize',
'std',
'sfm__estimator__selection',
'poly__degree',
'lr__copy_X',
'sfm__estimator__alphas',
'lr__fit_intercept',
'steps',
'poly__include_bias',
'sfm__estimator__eps']
Upvotes: 2
Views: 1613
Reputation: 66775
This is simple typographical error, you pass sfm_threshold
and you should sfm__threshold
(notice double underscore). At least this is what the error at the very beginning shows.
Upvotes: 6