8.3.8. sklearn.cross_validation.ShuffleSplit¶
- class sklearn.cross_validation.ShuffleSplit(n, n_iterations=10, test_fraction=0.1, train_fraction=None, indices=True, random_state=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_fraction : float (default 0.1)
Should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the test split.
train_fraction : float or None (default is None)
Should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the train split. 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_fraction=.25, random_state=0) >>> len(rs) 3 >>> print rs ... ShuffleSplit(4, n_iterations=3, test_fraction=0.25, indices=True, ...) >>> for train_index, test_index in rs: ... print "TRAIN:", train_index, "TEST:", 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_fraction=0.5, test_fraction=.25, random_state=0) >>> for train_index, test_index in rs: ... print "TRAIN:", train_index, "TEST:", test_index ... TRAIN: [3 1] TEST: [2] TRAIN: [2 1] TEST: [0] TRAIN: [0 2] TEST: [3]
- __init__(n, n_iterations=10, test_fraction=0.1, train_fraction=None, indices=True, random_state=None)¶