Skip to main content

Xgboost cross validation functions for time series data + gridsearch functions in R

✓ Published0🌍 Public
Aaakansh9
Last edited May 26, 2016
Created on May 26, 2016

This example shows a custom cross-validation function for XGBoost models on time-series data, using explicitly defined training and test index lists rather than random folds. The R code implements `xgb.ts.cv`, which extends the standard `xgb.cv` API by accepting separate `traininds` and `testinds` parameters, enabling chronological splits. It internally uses `xgb.ts.cv.mkfold` to create fold-specific boosters and watchlists, then iterates through boosting rounds with `xgb.iter.update` and `xgb.iter.eval`, aggregating results via `xgb.cv.aggcv`. The function supports early stopping, custom metrics, and prediction output, mirroring the original xgboost package’s cross-validation workflow.

AI-generated description