Reputation: 191
I'm trying to GridSearch the best hyperparameters with this code:
search =GridSearchCV(
make_pipeline(RobustScaler(),
SVR()#,
#cv=kf
#refit=True
),
param_grid = {
'estimator__svr__kernel': ('linear', 'rbf','poly')#,
#'estimator__svr__C':[ 10,20]
#'estimator__svr__gamma': [1e-5, 3e-4 ],
#'estimator__svr__epsilon':[0.001,0.002,0.006,0.008]#,
# 'cv' : [10]
},
refit=True)
search.fit(train, target)
I get this error :
ValueError: Invalid parameter estimator for estimator Pipeline(steps=[('robustscaler', RobustScaler()), ('svr', SVR())]). Check the list of available parameters with estimator.get_params().keys()
The error doesn't pin-point any particular entry in the parameter grid. Moreover, estimator.get_params().keys()
lists the prameters that I used:
dict_keys(['cv', 'error_score', 'estimator__memory', 'estimator__steps', 'estimator__verbose', 'estimator__robustscaler', 'estimator__svr', 'estimator__robustscaler__copy', 'estimator__robustscaler__quantile_range', 'estimator__robustscaler__unit_variance', 'estimator__robustscaler__with_centering', 'estimator__robustscaler__with_scaling', 'estimator__svr__C', 'estimator__svr__cache_size', 'estimator__svr__coef0', 'estimator__svr__degree', 'estimator__svr__epsilon', 'estimator__svr__gamma', 'estimator__svr__kernel', 'estimator__svr__max_iter', 'estimator__svr__shrinking', 'estimator__svr__tol', 'estimator__svr__verbose', 'estimator', 'n_jobs', 'param_grid', 'pre_dispatch', 'refit', 'return_train_score', 'scoring', 'verbose'])
No combination of param_grid seems to work.
Upvotes: 1
Views: 639
Reputation: 4653
I think that you should use square brackets instead of parentheses for the estimator__svr__kernel
:
'estimator__svr__kernel': ['linear', 'rbf','poly']
EDIT:
I was able to run your script against the iris dataset by using svr__kernel
instead of estimator__svr__kernel
in the paramter grid:
from sklearn.preprocessing import RobustScaler
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import make_pipeline
from sklearn.svm import SVR
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data[:, :2]
y = iris.target
search =GridSearchCV(
make_pipeline(RobustScaler(),
SVR()#,
#cv=kf
#refit=True
),
param_grid = {'svr__kernel': ('linear', 'rbf','poly')},
refit=True)
search.fit(X, y)
This returns:
GridSearchCV(estimator=Pipeline(steps=[('robustscaler', RobustScaler()),
('svr', SVR())]),
param_grid={'svr__kernel': ('linear', 'rbf', 'poly')})
Upvotes: 1