how to use GridSearchCV with custom estimator in sklearn?
There are 2 problems within your code:
You didn't specify
scoring
argument toGridSearchCV
. You seems be doing regression, somean_squared_error
is an option.Your
set_params
doesn't return reference to the object itself. You should addreturn self
after thefor
loop.As Andreas already mentioned, you rarely need to redefine
set_params
andget_params
in scikit-learn. Just having inherited from theBaseEstimator
should be enough.
You inherit from BaseEstimator. It should just work. See https://scikit-learn.org/dev/developers/develop.html
FYI this might be interesting to you: https://github.com/scikit-learn/scikit-learn/pull/3306