KFoldSplitter<T>
Models & Types · AiDotNet.Preprocessing.DataPreparation.Splitting.CrossValidation
K-Fold cross-validation splitter that divides data into k equal folds.
Inheritance: DataSplitterBase<T> → KFoldSplitter<T>
For Beginners
K-Fold cross-validation is one of the most important techniques in machine learning for getting reliable performance estimates.
How It Works
How It Works:
- Divide data into k equal parts (folds)
- For each fold:
- Use that fold as the test set
- Use the remaining k-1 folds as training
- Average the results across all k evaluations
Visual Example (5-Fold):
Industry Standard:
- k=5 for large datasets (>10,000 samples)
- k=10 for smaller datasets (1,000-10,000 samples)
Why Use K-Fold?
- More reliable than a single train/test split
- Every sample gets tested exactly once
- Good for limited data where you can’t afford to hold out a large test set
Constructors
| Constructor | Summary |
|---|---|
KFoldSplitter(int k, bool shuffle, int randomSeed) |
Creates a new K-Fold cross-validation splitter. |
Properties
| Property | Summary |
|---|---|
int NumSplits { get; } |
|
string Description { get; } |
Methods
| Method | Summary |
|---|---|
DataSplitResult<T> Split(Matrix<T> X, Vector<T> y) |
|
IEnumerable<DataSplitResult<T>> GetSplits(Matrix<T> X, Vector<T> y) |