Middle — Senior
What is early stopping in boosting and how to validate it correctly?
sobes.tech AI
Answer from AI
Early stopping is a method to prevent overfitting in boosting algorithms (e.g., XGBoost, LightGBM). The idea is to stop training when the model's performance on the validation set ceases to improve.
How it works:
- Data is split into training and validation sets.
- During training, after each iteration (adding a new base learner), the metric on the validation set is evaluated.
- If the metric does not improve for a specified number of iterations (
early_stopping_rounds), training is halted.
Proper validation:
- The validation set should be independent of the training set.
- The metric should reflect the task (e.g., AUC for classification).
- Use cross-validation with early stopping if possible to obtain a more reliable estimate.
Example in LightGBM:
import lightgbm as lgb
train_data = lgb.Dataset(X_train, label=y_train)
valid_data = lgb.Dataset(X_valid, label=y_valid)
params = {'objective': 'binary', 'metric': 'auc'}
model = lgb.train(params, train_data, valid_sets=[valid_data], early_stopping_rounds=10)
Thus, the model will stop if the validation performance does not improve over 10 iterations.