August 2019
Intermediate to advanced
342 pages
9h 35m
English
In the following example, we will use the k-folds cross validation implemented by the scikit-learn package, sklearn.model_selection. For simplicity, we will assign the value 2 to the variable k, thereby obtaining a 2-folds cross validation.
The sample dataset consists of just four samples. Therefore, each fold will contain two arrays to be used in turn, one for training and the other for testing. Finally, note how it is possible to associate the different folds with training and testing data, using the syntax provided by numpy indexing:
import numpy as npfrom sklearn.model_selection import KFoldX = np.array([[1., 0.], [2., 1.], [-2., -1.], [3., 2.]])y = np.array([0, 1, 0, 1])k_folds = KFold(n_splits=2)for ...
Read now
Unlock full access