StratifiedGroupKFoldStrategy<T>
Models & Types · AiDotNet.Evaluation.CrossValidation
Stratified Group K-Fold: combines stratification and group constraints.
Implements: ICrossValidationStrategy<T>
For Beginners
This strategy ensures both:
- Class distribution is preserved in each fold (stratification)
- Groups are kept together (no leakage between train/validation)
How It Works
Example use case: Medical study where:
- Multiple samples from the same patient (group = patient ID)
- Classes are imbalanced (disease vs. healthy)
- Need both group integrity and class balance
Constructors
| Constructor | Summary |
|---|---|
StratifiedGroupKFoldStrategy(int nFolds, int[] groups, int? randomSeed) |
Initializes Stratified Group K-Fold. |
Properties
| Property | Summary |
|---|---|
int NumSplits { get; } |
|
string Description { get; } |
|
string Name { get; } |
Methods
| Method | Summary |
|---|---|
IEnumerable<ValueTuple<int[], int[]>> Split(int dataSize, ReadOnlySpan<T> labels) |
|
void SetGroups(int[] groups) |
Sets the group identifiers. |