Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit xgboost execution time?

How to limit xgboost execution time (for example, I have a 'computational budget' 1 hour in cluster)? Also is it possible to limit xgboost in number of rounds?

like image 509
mrgloom Avatar asked Dec 21 '25 10:12

mrgloom


1 Answers

It is possible, if you're directly calling xgboost.train function, which is used by XGBModel.fit under the hood. This function has a num_boost_round parameter (to limit the number of boosting rounds) and callbacks parameter that you can use to check the running time and raise an EarlyStopException if needed. Of course, you can't stop in the middle of iteration, but in time_limit - delta minutes.

Unfortunately, XGBModel (and correspondingly XGBRegressor and XGBClassifier) API doesn't allow to pass the callbacks through, so you'll have to refactor your code to a low-level API:

params = {'eval_metric': True, ...}
trainDmatrix = DMatrix(X, label=y)
train(params, trainDmatrix, num_boost_round=10, callbacks=[callback])
like image 102
Maxim Avatar answered Dec 24 '25 00:12

Maxim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!