ananuc
ananuc

Reputation: 185

GBRT Hyperparameter Tuning using GridSearchCV

I'm running GridSearchCV to find the best parameters for GradientBoostingRegressor.

The tutorial given was to use MSE for scoring.

gs_cv = GridSearchCV(est, param_grid, scoring='mean_squared_error', n_jobs=4).fit(X_train, y_train)

Is it possible to use other own defined scoring such as Root Mean Squared Logarithmic Error (RMSLE) to get the best hyperparameters?

def rmsle(predicted, actual, size):
    return np.sqrt(np.nansum(np.square(np.log(predicted + 1) - np.log(actual + 1)))/float(size))

Upvotes: 1

Views: 1335

Answers (1)

elyase
elyase

Reputation: 40973

You need to make a custom scorer. In your case it would look like this:

from sklearn.metrics import make_scorer

scorer = make_scorer(rmsle, greater_is_better=False, size=10)
grid = GridSearchCV(est, param_grid, scoring=scorer)

Upvotes: 1

Related Questions