1. Learn
  2. /
  3. Courses
  4. /
  5. Winning a Kaggle Competition in Python

Connected

Exercise

Time K-fold

Remember the "Store Item Demand Forecasting Challenge" where you are given store-item sales data, and have to predict future sales?

It's a competition with time series data. So, time K-fold cross-validation should be applied. Your goal is to create this cross-validation strategy and make sure that it works as expected.

Note that the train DataFrame is already available in your workspace, and that TimeSeriesSplit has been imported from sklearn.model_selection.

Instructions

100 XP
  • Create a TimeSeriesSplit object with 3 splits.
  • Sort the train data by "date" column to apply time K-fold.
  • Loop over each time split using time_kfold object.
  • For each split select training and testing folds using train_index and test_index.