Skip to main content

StratifiedGroupKFoldSplitter

Splitter
DashAI.back.splitters.StratifiedGroupKFoldSplitter

Splitter that preserves both class balance and group membership in each fold.

This strategy is particularly valuable for grouped classification tasks where the target labels are imbalanced and the samples are also organized into non-independent groups. It simultaneously prevents leakage across groups and keeps the class distribution similar across folds, which makes the evaluation more reliable and less biased.

References

Parameters

n_splits : integer, default=5
Number of folds. Must be an integer between 2 and 20.
group_column, default=None
Name of the dataset column that identifies the group each sample belongs to. Samples that share the same group are always kept together in the same fold.
shuffle : boolean, default=True
Whether to shuffle each group's samples before splitting.
random_state : integer, default=42
Seed used to make the split reproducible.
test_size : number, default=0.1
Proportion of the dataset set aside as a test set. No fold and no hyperparameter search ever sees those rows, so they are scored once by the final model and are the data it can be explained on. Set it to 0 to cross-validate every row, which leaves the run without a test metric and without data to explain, and note that the fold metrics are validation estimates that may carry an optimistic bias if they are used as the final evaluation of the model.

Methods

split_indexes(self, x: 'DashAIDataset', y: 'DashAIDataset') -> 'List[Tuple[List, List]]'

Defined on StratifiedGroupKFoldSplitter

Generate train/test index pairs preserving both labels and groups.

Parameters

x : DashAIDataset
Input dataset that can be converted to a pandas DataFrame.
y : DashAIDataset
Target values used to preserve class balance across folds.

Returns

list[tuple]
A list of train/test index pairs preserving group and label balance.

explainable_partitions(cls, split_indexes)

Defined on FoldSplitter

Return the partitions of a fold based run an explainer may target.

Parameters

split_indexes : dict
The Run.split_indexes payload, already parsed.

Returns

dict
Row indexes for the train and test partitions.

explainable_splits(cls, split_indexes: 'Dict[str, Any]') -> 'List[Dict[str, Any]]'

Defined on BaseSplitter

Describe the partitions of a run that an explainer may target.

Parameters

split_indexes : dict
The Run.split_indexes payload, already parsed.

Returns

list[dict]
One {"name", "rows"} entry per non-empty partition, followed by an all entry. Empty when the run has no data to explain.

get_credential(self, name: str)

Defined on ConfigObject

Resolve a registered credential component by name.

Parameters

name : str
Credential component class name (e.g. "HuggingFaceCredential").

Returns

BaseCredential
An instance of the requested credential component.

get_metadata(cls) -> 'dict'

Defined on FoldSplitter

Return metadata describing the splitter's compatibility.

get_schema(cls) -> dict

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

prepare_y(self, y)

Defined on BaseSplitter

Encode the target variable for stratified splitting.

Parameters

y : object
Target values to encode. This may be a list, a pandas-like object, or a DashAI dataset that exposes a single target column.

Returns

object
Encoded labels suitable for stratified splitting.

split(self, x: 'DashAIDataset', y: 'DashAIDataset') -> 'Tuple[List[DatasetDict], List[DatasetDict], Dict[str, Any]]'

Defined on FoldSplitter

Create folds and return both the partitioned datasets and the indices.

Parameters

x : DashAIDataset
Input dataset to split.
y : DashAIDataset
Target values associated with x.

Returns

tuple[list, list, dict]
A tuple containing the split datasets for every fold and a mapping from fold names to their corresponding train/test indices.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.

Parameters

raw_data : dict
A dictionary with the data provided by the user to initialize the model.

Returns

dict
A validated dictionary with the necessary objects.

Compatible with