model_selection.KFold

K-Folds cross-validator Provides train/test indices to split data in train/test sets. Split dataset into k consecutive folds (without shuffling by default).

Each fold is then used once as a validation while the k - 1 remaining folds form the training set.

Usage

import { KFold } from 'kalimdor/model_selection';

const kFold = new KFold({ k: 5 });
const X1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
console.log(kFold.split({ X: X1, y: X1 }));

/* [ { trainIndex: [ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ],
*  testIndex: [ 0, 1, 2, 3 ] },
* { trainIndex: [ 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ],
*  testIndex: [ 4, 5, 6, 7 ] },
* { trainIndex: [ 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 17, 18, 19 ],
*  testIndex: [ 8, 9, 10, 11 ] },
* { trainIndex: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19 ],
*  testIndex: [ 12, 13, 14, 15 ] },
* { trainIndex: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ],
*  testIndex: [ 16, 17, 18, 19 ] } ]

Constructors

Methods

Constructors


constructor

new KFold(__namedParameters: `object`)

Defined in model_selection/_split.ts:32

Parameters:

ParamTypeDefaultDescription
options.knumber2Number of folds. Must be at least 2.
options.shufflebooleanfalseWhether to shuffle the data before splitting into batches.

Returns: KFold

Methods


λ split

Defined in model_selection/_split.ts:53

Parameters:

ParamTypeDefaultDescription
options.XanyTraining data, where nsamples is the number of samples and n_features is the number of features.
options.yanyThe target variable for supervised learning problems.

Returns:

any[]