You can use GridSearchCV
class from sklearn
to perform a grid search for hyperparameter tuning of XGBoost regressor. Here's an example code:
main.py760 chars25 lines
Here, we defined XGBRegressor()
object and then defined a hyperparameter search space for n_estimators
, max_depth
, learning_rate
, gamma
, colsample_bytree
, and subsample
parameters. Then GridSearchCV
is used to perform a 5-fold cross-validation grid search for the best hyperparameters. Finally, we printed the best hyperparameters and their corresponding best score.
gistlibby LogSnag