Skip to content

LearningCurveSplitter: option to keep sessions with too few trials in a per_class curve #1371

Open

Description

@bkowshik

With policy="per_class", a size above the smallest class in a session's training pool raises ValueError (_get_data_size_subsets). Folds are built for the whole dataset before any fit, so one short session stops that dataset's evaluation.

A real case: MOABB loads 45 trials per class for Zhou2016's subject 2, session 1, where the other sessions of subjects 1–2 have 50 or more. With test_size=0.2, a grid that reaches 40 works on the 50-trial sessions and raises on that one.

When sessions or datasets differ in trials per class, a learning curve has three choices today:

  • Stop the grid at the smallest session: no large sizes for anyone.
  • Use a grid per dataset: the large sizes average fewer sessions, so the curve moves with who is in the average as well as with the training size.
  • Use policy="ratio": every session stays, but the x-axis is no longer in trials.

Reproduce

import numpy as np
from moabb.evaluations.splitters import LearningCurveSplitter

y = np.array([0, 1] * 45)  # one session, 45 trials per class
cv = LearningCurveSplitter(
    data_size={"policy": "per_class", "value": [10, 20, 40]},
    n_perms=2, test_size=0.2, random_state=0,
)
list(cv.split(np.zeros(len(y)), y))
develop at 6f7b2eb45 | sklearn 1.6.1 | numpy 2.4.6
ValueError: Smallest class has 36 samples. Desired samples per class 40 is too large.

Proposal

  1. An opt-in clip. LearningCurveSplitter(..., on_few_trials="clip") trains on min(value, smallest class) per class instead of raising. The default, "raise", keeps today's behaviour. The name follows MNE's on_few_samples and NumPy's mode="clip"; another is fine.
  2. A result column with the requested size. data_size records the actual training-set size: per_class values 10, 20, 36 give data_size 20, 40, 72, so a clipped session would land on a different x. The same column helps ratio: sessions with 45 and 60 trials per class get data_size 36, 72 and 48, 96 for ratios 0.5 and 1.0, and the ratio is not in the results.

Every session then contributes to every point, the axis stays in trials per class, and data_size shows which points were clipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions