sklearn.cross_validation.LeaveOneLabelOut¶
- class sklearn.cross_validation.LeaveOneLabelOut(labels, indices=None)¶
Leave-One-Label_Out cross-validation iterator
Provides 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.
Parameters : labels : array-like of int with shape (n_samples,)
Arbitrary domain-specific stratification of the data to be used to draw the splits.
Examples
>>> from sklearn import cross_validation >>> 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_validation.LeaveOneLabelOut(labels) >>> len(lol) 2 >>> print(lol) sklearn.cross_validation.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: [2 3] TEST: [0 1] [[5 6] [7 8]] [[1 2] [3 4]] [1 2] [1 2] TRAIN: [0 1] TEST: [2 3] [[1 2] [3 4]] [[5 6] [7 8]] [1 2] [1 2]
- __init__(labels, indices=None)¶