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?
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With