Leave-One-Out and Leave-P-Out cross-validation splitters.
Classes
Leave-One-Out cross-validation.
Each sample is used once as test while remaining samples form training set.
Notes
This can be very slow for large datasets as it creates n splits.
python
>>> from tuiml.evaluation.splitting import LeaveOneOut
>>> import numpy as np
>>> X = np.arange(5).reshape(-1, 1)
>>> loo = LeaveOneOut()
>>> for train_idx, test_idx in loo.split(X):
... print(f"Train: {train_idx}, Test: {test_idx}")
Train: [1 2 3 4], Test: [0]
Train: [0 2 3 4], Test: [1]
Train: [0 1 3 4], Test: [2]
Train: [0 1 2 4], Test: [3]
Train: [0 1 2 3], Test: [4]
Methods
Leave-P-Out cross-validation.
P samples are used as test while remaining samples form training set. Generates all possible combinations.
Constructor
__init__( self, p: int = 2, )
Parameters
p
int
Size of test set.
Notes
Number of splits is C(n, p) = n! / (p! * (n-p)!) This grows very fast and can be impractical for large n or p.
python
>>> from tuiml.evaluation.splitting import LeavePOut
>>> import numpy as np
>>> X = np.arange(5).reshape(-1, 1)
>>> lpo = LeavePOut(p=2)
>>> for train_idx, test_idx in lpo.split(X):
... print(f"Train: {train_idx}, Test: {test_idx}")
Train: [2 3 4], Test: [0 1]
Train: [1 3 4], Test: [0 2]
Train: [1 2 4], Test: [0 3]
Train: [1 2 3], Test: [0 4]
Train: [0 3 4], Test: [1 2]
Train: [0 2 4], Test: [1 3]
Train: [0 2 3], Test: [1 4]
Train: [0 1 4], Test: [2 3]
Train: [0 1 3], Test: [2 4]
Train: [0 1 2], Test: [3 4]