Fork me on GitHub

sklearn.model_selection.LabelShuffleSplit

class sklearn.model_selection.LabelShuffleSplit(n_iter=5, test_size=0.2, train_size=None, random_state=None)[source]

Shuffle-Labels-Out cross-validation iterator

Provides randomized train/test indices to split data according to a third-party provided label. This label information can be used to encode arbitrary domain specific stratifications of the samples as integers.

For instance the labels could be the year of collection of the samples and thus allow for cross-validation against time-based splits.

The difference between LeavePLabelOut and LabelShuffleSplit is that the former generates splits using all subsets of size p unique labels, whereas LabelShuffleSplit generates a user-determined number of random test splits, each with a user-determined fraction of unique labels.

For example, a less computationally intensive alternative to LeavePLabelOut(p=10) would be LabelShuffleSplit(test_size=10, n_iter=100).

Note: The parameters test_size and train_size refer to labels, and not to samples, as in ShuffleSplit.

Parameters:

n_iter : int (default 5)

Number of re-shuffling & splitting iterations.

test_size : float (default 0.2), int, or None

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

train_size : float, int, or None (default is None)

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

random_state : int or RandomState

Pseudo-random number generator state used for random sampling.

Methods

get_n_splits([X, y, labels]) Returns the number of splitting iterations in the cross-validator
split(X[, y, labels]) Generate indices to split data into training and test set.
__init__(n_iter=5, test_size=0.2, train_size=None, random_state=None)[source]
get_n_splits(X=None, y=None, labels=None)[source]

Returns the number of splitting iterations in the cross-validator

Parameters:

X : object

Always ignored, exists for compatibility.

y : object

Always ignored, exists for compatibility.

labels : object

Always ignored, exists for compatibility.

Returns:

n_splits : int

Returns the number of splitting iterations in the cross-validator.

split(X, y=None, labels=None)[source]

Generate indices to split data into training and test set.

Parameters:

X : array-like, shape (n_samples, n_features)

Training data, where n_samples is the number of samples and n_features is the number of features.

y : array-like, shape (n_samples,)

The target variable for supervised learning problems.

labels : array-like, with shape (n_samples,), optional

Group labels for the samples used while splitting the dataset into train/test set.

Returns:

train : ndarray

The training set indices for that split.

test : ndarray

The testing set indices for that split.

Previous