Skip to content

Type incompatibility between sklearn's API and SlidingEstimator #12748

@hoechenberger

Description

@hoechenberger

I wanted to pass a SlidingEstimator instance to sklearn's cross_val_predict(), but it gets red squiggly lines:
Screenshot 2024-07-25 at 09 17 41

The error message is:

Argument of type "SlidingEstimator" cannot be assigned to parameter "estimator" of type "BaseEstimator" in function "cross_val_predict"
"SlidingEstimator" is incompatible with "BaseEstimator"

The reason is that SlidingEstimator doesn't inherit from sklearn's BaseEstimator, but from mne.fixes.BaseEstimator.

My current workaround is cast()ing the type:

from typing import cast
from sklearn.base import BaseEstimator

predictions = cross_val_predict(
    cast(BaseEstimator, model),
    X,
    labels["cue"],
    cv=cv,
    n_jobs=-1,
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions