Skip to content

xgboost/cv-shuffled-time-series

Pack Severity Fix Versions
XGBoost warning none, edit by hand All versions

xgboost.cv defaults to shuffle=True. On time-ordered data, random shuffling lets future observations leak into training folds (on a 200-step random walk, shuffle=True reported RMSE 0.507 against 0.623 with shuffle=False).

cv_res = xgb.cv(params, dtrain, num_boost_round=50, nfold=4)
cv_res = xgb.cv(params, dtrain, num_boost_round=50, folds=list(TimeSeriesSplit(n_splits=4).split(X)))

Calls to xgboost.cv omitting folds= and shuffle=False in a module that imports or uses a forward time-series splitter (TimeSeriesSplit, TimeGapSplit, GroupTimeSeriesSplit, WalkForward, or CombinatorialPurgedCV).

Pass forward folds= built from a time-series splitter, or set shuffle=False when contiguous ordered blocks are intended.

xgboost.cv defaults to shuffle=True, mixing future rows into training folds on time-ordered data. Pass folds= from a forward time-series splitter (or shuffle=False).

See all rules in the XGBoost pack.