Skip to content

sklearn_ module

Scikit-learn compatible class for splitting.


SplitterCV class

SplitterCV(
    splitter=None,
    *,
    splitter_cls=None,
    split_group_by=None,
    set_group_by=None,
    template_context=None,
    **splitter_kwargs
)

Scikit-learn compatible cross-validator based on Splitter.

Usage

  • Replicate TimeSeriesSplit from scikit-learn:
>>> from vectorbtpro import *

>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
>>> y = np.array([1, 2, 3, 4])

>>> cv = vbt.SplitterCV(
...     "from_expanding",
...     min_length=2,
...     offset=1,
...     split=-1
... )
>>> for i, (train_indices, test_indices) in enumerate(cv.split(X)):
...     print("Split %d:" % i)
...     X_train, X_test = X[train_indices], X[test_indices]
...     print("  X:", X_train.tolist(), X_test.tolist())
...     y_train, y_test = y[train_indices], y[test_indices]
...     print("  y:", y_train.tolist(), y_test.tolist())
Split 0:
  X: [[1, 2]] [[3, 4]]
  y: [1] [2]
Split 1:
  X: [[1, 2], [3, 4]] [[5, 6]]
  y: [1, 2] [3]
Split 2:
  X: [[1, 2], [3, 4], [5, 6]] [[7, 8]]
  y: [1, 2, 3] [4]

Superclasses

  • Base
  • sklearn.model_selection._split.BaseCrossValidator
  • sklearn.utils._metadata_requests._MetadataRequester

Inherited members


get_n_splits method

SplitterCV.get_n_splits(
    X=None,
    y=None,
    groups=None
)

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


get_splitter method

SplitterCV.get_splitter(
    X=None,
    y=None,
    groups=None
)

Get splitter of type Splitter.


set_group_by class property

Set groups. See BaseIDXAccessor.get_grouper.

Not passed to the factory method.


split method

SplitterCV.split(
    X=None,
    y=None,
    groups=None
)

Generate indices to split data into training and test set.


split_group_by class property

Split groups. See BaseIDXAccessor.get_grouper.

Not passed to the factory method.


splitter class property

Splitter.

Either as a Splitter instance, a factory method name, or the factory method itself.

If None, will be determined automatically based on SplitterCV.splitter_kwargs.


splitter_cls class property

Splitter class.

Defaults to Splitter.


splitter_kwargs class property

Keyword arguments passed to the factory method.


template_context class property

Mapping used to substitute templates in ranges.

Passed to the factory method.