how to use GridSearchCV with custom estimator in sklearn?

There are 2 problems within your code:

  1. You didn't specify scoring argument to GridSearchCV. You seems be doing regression, so mean_squared_error is an option.

  2. Your set_params doesn't return reference to the object itself. You should add return self after the for loop.

    As Andreas already mentioned, you rarely need to redefine set_params and get_params in scikit-learn. Just having inherited from the BaseEstimator 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