Warning: This documentation is for scikit-learn version 0.12.1. — Latest stable version

8.3.8. sklearn.cross_validation.ShuffleSplit

class sklearn.cross_validation.ShuffleSplit(n, n_iterations=10, test_size=0.1, train_size=None, indices=True, random_state=None, test_fraction=None, train_fraction=None)

Random permutation cross-validation iterator.

Yields indices to split data into training and test sets.

Note: contrary to other cross-validation strategies, random splits do not guarantee that all folds will be different, although this is still very likely for sizeable datasets.

Parameters :

n : int

Total number of elements in the dataset.

n_iterations : int (default 10)

Number of re-shuffling & splitting iterations.

test_size : float (default 0.1) or int

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.

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 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 fraction.

indices : boolean, optional (default True)

Return train/test split as arrays of indices, rather than a boolean mask array. Integer indices are required when dealing with sparse matrices, since those cannot be indexed by boolean masks.

random_state : int or RandomState

Pseudo-random number generator state used for random sampling.

See also

Bootstrap
cross-validation using re-sampling with replacement.

Examples

>>> from sklearn import cross_validation
>>> rs = cross_validation.ShuffleSplit(4, n_iterations=3,
...     test_size=.25, random_state=0)
>>> len(rs)
3
>>> print(rs)
... 
ShuffleSplit(4, n_iterations=3, test_size=0.25, indices=True, ...)
>>> for train_index, test_index in rs:
...    print("TRAIN: %s TEST: %s" % (train_index, test_index))
...
TRAIN: [3 1 0] TEST: [2]
TRAIN: [2 1 3] TEST: [0]
TRAIN: [0 2 1] TEST: [3]
>>> rs = cross_validation.ShuffleSplit(4, n_iterations=3,
...     train_size=0.5, test_size=.25, random_state=0)
>>> for train_index, test_index in rs:
...    print("TRAIN: %s TEST: %s" % (train_index, test_index))
...
TRAIN: [3 1] TEST: [2]
TRAIN: [2 1] TEST: [0]
TRAIN: [0 2] TEST: [3]
__init__(n, n_iterations=10, test_size=0.1, train_size=None, indices=True, random_state=None, test_fraction=None, train_fraction=None)
Previous
Next