This page

scikits.learn.cross_val.LeaveOneLabelOut

class scikits.learn.cross_val.LeaveOneLabelOut(labels, indices=False)

Leave-One-Label_Out cross-validation iterator

Provides train/test indices to split data in train test sets

__init__(labels, indices=False)

Leave-One-Label_Out cross validation

Provides train/test indices to split data in train test sets

Parameters :

labels : list

List of labels

indices: boolean, optional (default False) :

Return train/test split with integer indices or boolean mask. Integer indices are useful when dealing with sparse matrices that cannot be indexed by boolean masks.

Examples

>>> from scikits.learn import cross_val
>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
>>> y = np.array([1, 2, 1, 2])
>>> labels = np.array([1, 1, 2, 2])
>>> lol = cross_val.LeaveOneLabelOut(labels)
>>> len(lol)
2
>>> print lol
scikits.learn.cross_val.LeaveOneLabelOut(labels=[1 1 2 2])
>>> for train_index, test_index in lol:
...    print "TRAIN:", train_index, "TEST:", test_index
...    X_train, X_test = X[train_index], X[test_index]
...    y_train, y_test = y[train_index], y[test_index]
...    print X_train, X_test, y_train, y_test
TRAIN: [False False  True  True] TEST: [ True  True False False]
[[5 6]
 [7 8]] [[1 2]
 [3 4]] [1 2] [1 2]
TRAIN: [ True  True False False] TEST: [False False  True  True]
[[1 2]
 [3 4]] [[5 6]
 [7 8]] [1 2] [1 2]