Regarding the question of whether Kfold cross-validation is applicable to time series data, I've read some answers from stackexchange and blog posts from other sources as well, and they state that we cannot apply Kfold cross-validation to time series modeling (eg. Don’t Use K-fold Validation for Time Series Forecasting, Using k-fold cross-validation for time-series model selection).

But in the Tabular Playground Series - Jul 2021 competition on Kaggle, I found some senior participants apply this approach (eg: stacked model, TPS-Jul-XGBoost Regressor optimized with Hyperopt, etc.), even set KFold(n_splits=self.n_folds, shuffle=True).

So I'm a little confused, is their approach justified? Thanks.


Time series cross validation


1 Answer 1


These posts refer specifically to time series forecasting - building predictive models using information about the trends and cycles in the historical data. Applying Kfold cross-validation risks (a) losing the temporal relationships due to gaps in the time series and (b) building models where future information is used in the predictions.

Neither of the two Kaggle notebooks you reference are doing time series forecasting, even though the data could be considered a (multivariate) time series. They treat each time step as an independent instance and ignore any time-dependency between the instances - in other words as regular tabular data, so there's no problem using Kfold cross-validation in this case.

  • $\begingroup$ Thank you for answering my question. From your point of view: If I want to build a model to predict the Nasdaq index or stock prices, could I use k-fold cross-validation? $\endgroup$
    – ah bon
    Nov 1, 2022 at 1:12
  • 1
    $\begingroup$ @ahbon - I know very little about forecasting models, so I can't really help you with that question. $\endgroup$
    – Lynn
    Nov 1, 2022 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.