moabb.evaluations.WithinSessionSplitter#

class moabb.evaluations.WithinSessionSplitter(n_folds: int = 5, shuffle: bool = True, random_state: int | None = None, cv_class: type[~sklearn.model_selection._split.BaseCrossValidator] = <class 'sklearn.model_selection._split.StratifiedKFold'>, **cv_kwargs: dict)[source]#

Data splitter for within session evaluation.

Within-session evaluation uses k-fold cross_validation to determine train and test sets for each subject in each session. This splitter assumes that all data from all subjects is already known and loaded.

The schematic diagram of the WithinSession split

The inner cross-validation strategy can be changed by passing the cv_class and cv_kwargs arguments. By default, it uses StratifiedKFold.

Parameters:
  • n_folds (int, default=5) – Number of folds. Must be at least 2. If

  • shuffle (bool, default=True) – Whether to shuffle each class’s samples before splitting into batches. Note that the samples within each split will not be shuffled.

  • random_state (int, RandomState instance or None, default=None) – Controls the randomness of splits. Only used when shuffle is True. Pass an int for reproducible output across multiple function calls.

  • cv_class (cros-validation class, default=StratifiedKFold) – Inner cross-validation strategy for splitting the sessions.

  • cv_kwargs (dict) – Additional arguments to pass to the inner cross-validation strategy.

get_n_splits(metadata)[source]#

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

split(y, metadata)[source]#

Generate indices to split data into training and test set.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data, where n_samples is the number of samples and n_features is the number of features.

  • y (array-like of shape (n_samples,)) – The target variable for supervised learning problems.

  • groups (array-like of shape (n_samples,), default=None) – Group labels for the samples used while splitting the dataset into train/test set.

Yields:
  • train (ndarray) – The training set indices for that split.

  • test (ndarray) – The testing set indices for that split.