skada.model_selection.DomainShuffleSplit

class skada.model_selection.DomainShuffleSplit(n_splits=10, *, test_size=None, train_size=None, random_state=None, under_sampling=0.8)[source]

Domain-Shuffle-Split cross-validator.

Provides randomized train/test indices to split data depending on their sample_domain. Each fold is composed of samples coming from both source and target domains. The folds are made by preserving the percentage of samples for each sample domain.

Parameters:
n_splitsint, default=10

Number of re-shuffling & splitting iterations.

test_sizefloat or int, default=None

If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the test split. If int, represents the absolute number of test samples. If None, the value is set to the complement of the train size. If train_size is also None, it will be set to 0.1.

train_sizefloat or int, default=None

If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the train split. If int, represents the absolute number of train samples. If None, the value is automatically set to the complement of the test size.

random_stateint or RandomState instance, default=None

Controls the randomness of the training and testing indices produced.

Examples

>>> import numpy as np
>>> from skada.model_selection import DomainShuffleSplit
>>> X = np.ones((10, 2))
>>> y = np.ones((10, 1))
>>> sample_domain = np.array([1, -2, 1, -2, 1, -2, 1, -2, 1, -2])
>>> rsdas = DomainShuffleSplit(
...     n_splits=3,
...     random_state=0,
...     test_size=0.1,
...     )
>>> for train_index, test_index in rsdas.split(X, y, sample_domain):
...     print("TRAIN:", train_index, "TEST:", test_index)
TRAIN: [4 2 0 1 3 9] TEST: [6 5]
TRAIN: [8 6 2 5 3 9] TEST: [4 7]
TRAIN: [8 2 6 3 1 9] TEST: [4 5]
set_split_request(*, sample_domain: bool | None | str = '$UNCHANGED$') DomainShuffleSplit

Request metadata passed to the split method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to split if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to split.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_domainstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_domain parameter in split.

Returns:
selfobject

The updated object.

Examples using skada.model_selection.DomainShuffleSplit

Visualizing cross-validation behavior in skada

Visualizing cross-validation behavior in skada