GroupKFoldSplitter
Splitter that generates folds while preserving the group structure of the data.
This strategy is useful when samples are not independent because they share a common group, such as a patient, document, image collection, or other entity that should not appear in both train and test partitions. It helps prevent leakage by keeping all observations from the same group within the same fold.
It is commonly applied in grouped classification, regression, and translation settings where group-level dependencies must be respected.
References
Parameters
- n_splits : integer, default=
5 - Number of folds. Must be an integer greater than or equal to 2.
- 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=
False - Whether to shuffle the groups before assigning them to folds.
- random_state : integer, default=
42 - Seed used to make the split reproducible when shuffle is enabled.
Methods
split_indexes(self, x: 'DashAIDataset', y: 'DashAIDataset') -> 'List[Tuple[List, List]]'
GroupKFoldSplitterGenerate train/test index pairs while keeping groups together.
Parameters
- x : DashAIDataset
- Input dataset that can be converted to a pandas DataFrame.
- y : DashAIDataset
- Target values associated with
x. This argument is accepted for interface consistency but is not used directly by the splitter.
Returns
- list[tuple]
- A list of train/test index pairs preserving the group assignments.
get_credential(self, name: str)
ConfigObjectResolve 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'
FoldSplitterReturn metadata describing the splitter's compatibility.
get_schema(cls) -> dict
ConfigObjectGenerates the component related Json Schema.
Returns
- dict
- Dictionary representing the Json Schema of the component.
prepare_y(self, y)
BaseSplitterEncode 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]]'
FoldSplitterCreate 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
ConfigObjectIt 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.