Preprocessing splitting - CyrilB1531/lodestar GitHub Wiki

Home › Preprocessing

Splitting — Lodestar.Preprocessing

One entry point, Splitters: it cuts the rows into cross-validation folds or into a single train and test split, at sklearn.model_selection parity wherever the reference is deterministic.

Indices in, indices out. A splitter here never sees the data. It is told how many rows there are — or, to stratify, what class each row belongs to — and it hands back the row numbers that train and the row numbers that are held out. Nothing is copied, and nothing decides the caller's layout.

Why this exists when ML.NET splits data

ML.NET has TrainTestSplit(IDataView, double, …) and CrossValidationSplit(IDataView, int, …), and both return data views. They also never stratify: dotnet/machinelearning#4396 has asked for it since 2019 and is open. samplingKeyColumnName keeps rows that share a key together, which is the opposite operation — it prevents a group from straddling the split, where stratifying spreads a class across every fold.

SharpLearning.CrossValidation does stratify, and its StratifiedIndexSampler<T> always shuffles from a seed, so it cannot reproduce a scikit-learn fold. What is missing in .NET is a splitter that is framework-free and reproducible, which is what decision 0004 wrote this for.

scikit-learn's seed, or a permutation

Every shuffled splitter takes randomState, scikit-learn's own random_state: numpy's legacy generator is replayed call for call, so the folds are the reference's for the same seed (decision 0008). NumSharp and NumpyDotNet reproduce that generator too, and neither can be a dependency of a core package.

KFold, StratifiedKFold and TrainTest also take order, a permutation of 0..nāˆ’1 they read the rows in. Passing your own gives a split this package can describe exactly without any generator — the same choice KMeansOptions.InitialCentres makes by taking the centres. The stratified train/test split has no such form: the reference breaks ties between classes at random, and no permutation carries that choice.

Types

Type What it is
Splitters The splitters.
FoldSplit One fold: which rows train, and which are held out.
TrainTestSplit A single train and test split of the rows.

See also