GridSearchCV with custom scorer that takes in hyperparameters

Viewed 26

Doing hyperparameter tuning with GridSearchCV, initial code looks like this

params = {'max_depth' : [3, 5, 8, 10],
          'max_features' : [3, 4, 5],
          'min_samples_leaf' : [10, 20, 50]}
model = model_selection.GridSearchCV(ensemble.RandomForestRegressor(n_estimators = 10, random_state = 100),
                                  params,
                                  cv = model_selection.KFold(n_splits = 3, shuffle = True, random_state = 2023),
                                  scoring = 'neg_mean_absolute_error')

However, instead of scoring with mean absolute error, I want to score with mean absolute error transformed by a hyperparameter that was given in the param grid. For example if I wanted to score with mean absolute error multiplied by the max_depth. I've tried writing custom scorers but cant seem to pass the parameters into the custom scorer function?

0 Answers
Related