Search code examples
pythonscikit-learncross-validation

<RandomizedSearchCV> Pass the estimator obtained after fitting to scoring function as a parameter


Suppose I want to do a RandomizedSearchCV with custom both estimator and scorer :

RandomizedSearchCV(cxCustomLogReg(), search_space,
                   n_iter=50, scoring=scorer) 

May it be possible, during randomized search, to pass the estimator obtained after fitting cxCustomLogReg() to scorer function as a parameter (and not only y_true/y_pred values as usual)?


Solution

  • This is actually the expected format. When scoring is a callable, it should have signature (fitted_estimator, X_test, y_test).

    You may be using the helper make_scorer, which converts a metric function with signature (y_true, y_pred) into a scoring function as described above. Just don't use that helper, and define your scorer directly.