Preprocessing splitters repeatedstratifiedkfold - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Preprocessing is 0.2.0 โ€” read its documentation.

Home โ€บ Preprocessing โ€บ Splitting

Splitters.RepeatedStratifiedKFold

Repeats shuffled stratified k-fold, as RepeatedStratifiedKFold does.

public static IReadOnlyList<FoldSplit> RepeatedStratifiedKFold(ReadOnlySpan<int> labels, int foldCount, int repeatCount, long randomState)

Parameters โ€” labels is one class label per row. foldCount is how many folds each repeat cuts. repeatCount is how many repeats, at least one. randomState is scikit-learn's random_state, in [0, 2ยณยฒ โˆ’ 1].

Returns โ€” repeatCount ยท foldCount folds, repeat by repeat, each index list ascending.

Exceptions โ€” ArgumentOutOfRangeException when a count or randomState is out of range. ArgumentException when foldCount is above every class's count. ArgumentException also when the folds times the classes are more cells than one array holds (#1314). ArgumentException also when the repeats times the folds are more splits than one list holds (#1318).

Example โ€” twelve rows in three classes, three folds, two repeats.

using Lodestar.Preprocessing;

int[] labels = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2];

IReadOnlyList<FoldSplit> folds = Splitters.RepeatedStratifiedKFold(labels, foldCount: 3, repeatCount: 2, randomState: 0);

int count = folds.Count;                                        // => 6
string first = string.Join(",", folds[0].TestIndices);          // => 2,4,7,11
string fourth = string.Join(",", folds[3].TestIndices);         // => 1,5,6,10

Remarks โ€” each repeat is Splitters.StratifiedKFold with a seed, drawing from the one generator the repeats share.

Applies to โ€” net10.0, netstandard2.0.

See also โ€” Splitters.RepeatedKFold, Splitters.StratifiedKFold.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ