Interpreting sklearns' GridSearchCV best score

The regressor.best_score_ is the average of r2 scores on left-out test folds for the best parameter combination.

In your example, the cv=5, so the data will be split into train and test folds 5 times. The model will be fitted on train and scored on test. These 5 test scores are averaged to get the score. Please see documentation:

"best_score_: Mean cross-validated score of the best_estimator"

The above process repeats for all parameter combinations. And the best average score from it is assigned to the best_score_.

You can look at my other answer for complete working of GridSearchCV

After finding the best parameters, the model is trained on full data.

r2_score(y_pred = best.predict(X), y_true = y)

is on the same data as the model is trained on, so in most cases, it will be higher.


The question linked by @Davide in the comments has answers why you get a positive R2 score - your model performs better than a constant prediction. At the same time you can get negative values in other situation, if your models there perform bad.

the reason for the difference in values is that regressor.best_score_ is evaluated on a particular fold out of the 5-fold split that you do, whereas r2_score(y_pred = best.predict(X), y_true = y) evaluates the same model (regressor.best_estimator_) but on the full sample (including the (5-1)-fold sub-set that was used to train that estimator)