mapie.subsample.BlockBootstrap

class mapie.subsample.BlockBootstrap(n_resamplings: int = 30, length: int | None = None, n_blocks: int | None = None, overlapping: bool = False, random_state: int | RandomState | None = None)[source]

Generate a sampling method, that block bootstraps the training set. It can replace KFold, LeaveOneOut or SubSample as cv argument in the TimeSeriesRegressor class.

Parameters:
n_resamplingsint

Number of resamplings. By default 30.

length: int

Length of the blocks. By default None, the length of the training set divided by n_blocks.

overlapping: bool

Whether the blocks can overlap or not. By default False.

n_blocks: int

Number of blocks in each resampling. By default None, the size of the training set divided by length.

random_state: Optional

int or RandomState instance.

Raises:
ValueError

If both length and n_blocks are None.

Examples

>>> import numpy as np
>>> from mapie.subsample import BlockBootstrap
>>> cv = BlockBootstrap(n_resamplings=2, length=3, random_state=0)
>>> X = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> for train_index, test_index in cv.split(X):
...    print(f"train index is {train_index}, test index is {test_index}")
train index is [0 1 2 3 4 5 0 1 2 3 4 5], test index is [8 9 6 7]
train index is [3 4 5 6 7 8 0 1 2 6 7 8], test index is [9]
__init__(n_resamplings: int = 30, length: int | None = None, n_blocks: int | None = None, overlapping: bool = False, random_state: int | RandomState | None = None) None[source]
get_n_splits(*args: Any, **kargs: Any) int[source]

Returns the number of splitting iterations in the cross-validator.

Returns:
int

Returns the number of splitting iterations in the cross-validator.

split(X: ndarray[tuple[Any, ...], dtype[_ScalarT]], *args: Any, **kargs: Any) Generator[Tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]], None, None][source]

Generate indices to split data into training and test sets.

Parameters:
XNDArray of shape (n_samples, n_features)

Training data.

Yields:
trainNDArray of shape (n_indices_training,)

The training set indices for that split.

testNDArray of shape (n_indices_test,)

The testing set indices for that split.

Raises:
ValueError

If length is not positive or greater than the train set size.

Examples using mapie.subsample.BlockBootstrap

Tutorial for time series

Tutorial for time series

EnbPI technique for time series

EnbPI technique for time series