In the quest to find the best model, you can view the indices of cross-validation folds and see what data is in each fold.
K-fold cross validation
Getting ready
Create a toy dataset that is very small:
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8],[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([1, 2, 1, 2, 1, 2, 1, 2])
How to do it..
- Import KFold and select the number of splits:
from sklearn.model_selection import KFold
kf= KFold(n_splits = 4)
- You can iterate through the generator and print out the indices:
cc = 1
for train_index, test_index in kf.split...