Added new train_folds parameter for xgb.cv() #5064
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New parameter and code allows user to select which indices will be used for training in each cross-validation fold if desired. This is to be used in conjunction with the existing folds parameter.
Currently, xgb.cv() assumes that if folds is not NULL, the given indices are to be used for the validation sets for each cross-validation fold, and all remaining indices should be used for training in each respective fold. Adding a train_folds parameter to specify which indices are to be used for the training set for each fold allows the implementation of a walk-forward or rolling window approach to cross-validation.
I came across this code on stackoverflow, where it was originally contributed by @RolandASc.
https://stackoverflow.com/questions/32433458/how-to-specify-train-and-test-indices-for-xgb-cv-in-r-package-xgboost/51412073