Open JSAnandEOS opened 3 years ago
I tried fitting a new XGBoost model for each fold of data using the same parameters as xgb_cv.best_estimator_
:
xgb_best_params = xgb_cv.best_estimator_.get_xgb_params()
for p in range(5):
xgb_temp = XGBRegressor(**xgb_best_params)
xgb_temp.fit(X_train.iloc[kfold_indexes[p]['train']].values, y_train.iloc[kfold_indexes[p]['train']].values)
print(xgb_temp.score(X_train.iloc[kfold_indexes[p]['test']].values, y_train.iloc[kfold_indexes[p]['test']].values)
This gives me values that are much closer to the original CV scores, but they are still not exactly the same:
0.81142551,
0.82771065,
0.87877982,
0.88612015,
0.70819454
Why would there still be a discrepancy if the exact same folds and parameters are used? Is BayesSearchCV doing something else with XGBoost inside the fitting process that I'm not aware of, or is this an issue with precision?
I tried replacing BayesSearchCV
with sklearn's RandomizedSearchCV
, and I my problem disappears when fitting for 5 CV folds. So it would seem that BayesSearchCV
is the issue here.
However, when I tried using 2 CV folds, I found that the 2nd fold's score was different as before, so does that mean that there is something wrong with XGBoost
instead? Why would this produce two different scores when provided the exact same parameters, data, and random seeds each time?
Hello @JSAnandEOS! I am having a similar issue myself. I too believe there is some kind of issue with the results of best_score_
. In my use case, I aim at scores on the order of e-12
but best_score_
is in the order of e-6
which suggests it should be doing awfully but test score and train score are on e-12
. In my case, I pass a scorer function. The only alternative I can think of is that there is a modification of the scoring values being performed somewhere internally, something close to a sqrt()
maybe?
BayesSearchCV
had been recently revamped. Make sure you're testing with the git master rather than the currently released version.
@kernc I am using the git master version.
I'm using BayesSearchCV to optimise an XGBoost model to fit some data I have. While the model fits fine, I am puzzled by the scores provided in the diagnostic information and am unable to replicate them.
Here's an example script using the Boston house prices dataset to illustrate my point:
After running this, xgb_cv.bestscore is 0.816, and xgb_cv.bestindex is 3. Looking at xgb_cv.cvresults, I want to find the best scores for each fold:
Which gives:
I'm not sure what's being calculated here, because
scoring
is set toNone
in my code. XGBoost's documentation isn't much help, but according toxgb_cv.best_estimator_.score?
it's supposed to be the R2 of the predicted values. Anyway, I'm unable to obtain these values when I manually try calculating the score for each fold of the data used in the fit:Which gives me the following:
How is BayesSearchCV calculating the scores for each fold, and why can't I replicate them using the
score
function? I would be most grateful for any assistance with this issue.(Also, manually calculating the mean of these scores gives: 0.8156560..., while
xgb_cv.best_score_
gives: 0.8159277... Not sure why there's a precision difference here.)