kfold

Provides train and validation indices for cross validation.

Attention: Available only with Activate commercial edition.

Syntax

output = kfold(X, num_folds, seed)

Inputs

X
Input dataset which need to be splitted.
Type: double
Dimension: logical
options
Type: struct
num_folds
Number of folds for splitting dataset (default: 5).
Type: integer
Dimension: scalar
shuffle
Flag to shuffle the dataset or not (default: false).
Type: Boolean
Dimension: logical
seed
Random seed used for shuffling.
Type: integer
Dimension: scalar

Outputs

output
Type: struct
folds
Cell used by 'getfold' method to retrieve folds in iterations.
Dimension: cell
num_folds
Number of folds used while splitting.
Type: integer
Dimension: scalar

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 
=============