I'm trying to implement a SGDClassifier with sklearn, but I'm getting this error:
ValueError: Invalid parameter loss for estimator Pipeline. Check the list of available parameters with `estimator.get_params().keys()`.
This is my code:
pipeline = Pipeline([
('clf', SGDClassifier())
])
parameters = {
'seed': [0],
'loss': ('log', 'hinge'),
'penalty': ['l1', 'l2', 'elasticnet'],
'alpha': [0.001, 0.0001, 0.00001, 0.000001]
}
score_func = make_scorer(metrics.f1_score)
grid_search = GridSearchCV(pipeline, parameters, n_jobs=3,
verbose=1, scoring=score_func)
grid_search.fit(X, Y)
How can I fix this?
From the User's Guide:
Parameters of the estimators in the pipeline can be accessed using the <estimator>__<parameter> syntax
So try this:
parameters = {
'clf__seed': [0],
'clf__loss': ('log', 'hinge'),
'clf__penalty': ['l1', 'l2', 'elasticnet'],
'clf__alpha': [0.001, 0.0001, 0.00001, 0.000001]
}
This displays exact keys to be used to reference parameters within the pipeline
pipeline.get_params().keys()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With