GapLeavePOut
- class tscv.GapLeavePOut(p, gap_before=0, gap_after=0)[source]
Leave-P-Out cross-validator with Gaps
Provides train/test indices to split data in train/test sets. This results in testing on only contiguous samples of size p, while the remaining samples (with the gaps removed) form the training set in each iteration.
- Parameters
- pint
Size of the test sets.
- gap_beforeint, default=0
Gap before the test sets.
- gap_afterint, default=0
Gap after the test sets.
Examples
>>> import numpy as np >>> from tscv import GapLeavePOut >>> glpo = GapLeavePOut(2, 1, 1) >>> glpo.get_n_splits([0, 1, 2, 3, 4]) 4 >>> print(glpo) GapLeavePOut(gap_after=1, gap_before=1, p=2) >>> for train_index, test_index in glpo.split([0, 1, 2, 3, 4]): ... print("TRAIN:", train_index, "TEST:", test_index) TRAIN: [3 4] TEST: [0 1] TRAIN: [4] TEST: [1 2] TRAIN: [0] TEST: [2 3] TRAIN: [0 1] TEST: [3 4]
- get_n_splits(X, y=None, groups=None)[source]
Returns the number of splitting iterations in the cross-validator
- Parameters
- Xarray-like, shape (n_samples, n_features)
Training data, where n_samples is the number of samples and n_features is the number of features.
- yobject
Always ignored, exists for compatibility.
- groupsobject
Always ignored, exists for compatibility.
- split(X, y=None, groups=None)
Generate indices to split data into training and test set.
- Parameters
- Xarray-like, shape (n_samples, n_features)
Training data, where n_samples is the number of samples and n_features is the number of features.
- yarray-like, of length n_samples
The target variable for supervised learning problems.
- groupsarray-like, with shape (n_samples,), optional
Group labels for the samples used while splitting the dataset into train/test set.
- Yields
- trainndarray
The training set indices for that split.
- testndarray
The testing set indices for that split.