kfold
Provides train and validation indices for cross validation.
Syntax
output = kfold(X, num_folds, seed)
Inputs
- X
- Input dataset which need to be splitted.
- options
- Type: struct
Outputs
- output
- Type: struct
Example
Usage of kfold
X = [1 2; 3 4; 1 2; 3 4];
options.num_folds = 3;
options.seed = 234;
options.shuffle = true;
folds = kfold(X, options);
for fold_count=1:folds.num_folds
[train_idxs, valid_idxs] = getfold(folds, fold_count);
printf('\nTRAIN: '); printf('%d ', train_idxs);
printf('\nVALID: '); printf('%d ', valid_idxs);
printf('\n=============');
end
TRAIN: 1 4
VALID: 3 2
=============
TRAIN: 2 3 4
VALID: 1
=============
TRAIN: 1 2 3
VALID: 4
=============