mne.decoding.SlidingEstimator#

class mne.decoding.SlidingEstimator(base_estimator, scoring=None, n_jobs=None, *, position=0, allow_2d=False, verbose=None)[source]#

Search Light.

Fit, predict and score a series of models to each subset of the dataset along the last dimension. Each entry in the last dimension is referred to as a task.

Parameters:
base_estimatorobject

The base estimator to iteratively fit on a subset of the dataset.

scoringcallable() | str | None

Score function (or loss function) with signature score_func(y, y_pred, **kwargs). Note that the “predict” method is automatically identified if scoring is a string (e.g. scoring='roc_auc' calls predict_proba), but is not automatically set if scoring is a callable (e.g. scoring=sklearn.metrics.roc_auc_score).

n_jobsint | None

The number of jobs to run in parallel. If -1, it is set to the number of CPU cores. Requires the joblib package. None (default) is a marker for ‘unset’ that will be interpreted as n_jobs=1 (sequential execution) unless the call is performed under a joblib.parallel_config context manager that sets another value for n_jobs.

positionint

The position for the progress bar.

allow_2dbool

If True, allow 2D data as input (i.e. n_samples, n_features).

verbosebool | str | int | None

Control verbosity of the logging output. If None, use the default verbosity level. See the logging documentation and mne.verbose() for details. Should only be passed as a keyword argument.

Attributes:
estimators_array_like, shape (n_tasks,)

List of fitted scikit-learn estimators (one per task).

Methods

decision_function(X)

Estimate distances of each data slice to the hyperplanes.

fit(X, y, **fit_params)

Fit a series of independent estimators to the dataset.

fit_transform(X, y, **fit_params)

Fit and transform a series of independent estimators to the dataset.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predict each data slice/task with a series of independent estimators.

predict_proba(X)

Predict each data slice with a series of independent estimators.

score(X, y)

Score each estimator on each task.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Transform each data slice/task with a series of independent estimators.

decision_function(X)[source]#

Estimate distances of each data slice to the hyperplanes.

Parameters:
Xarray, shape (n_samples, nd_features, n_tasks)

The input samples. For each data slice, the corresponding estimator outputs the distance to the hyperplane, e.g.: [estimators[ii].decision_function(X[..., ii]) for ii in range(n_estimators)]. The feature dimension can be multidimensional e.g. X.shape = (n_samples, n_features_1, n_features_2, n_estimators).

Returns:
y_predarray, shape (n_samples, n_estimators, n_classes * (n_classes-1) // 2)

Predicted distances for each estimator/data slice.

Notes

This requires base_estimator to have a decision_function method.

fit(X, y, **fit_params)[source]#

Fit a series of independent estimators to the dataset.

Parameters:
Xarray, shape (n_samples, nd_features, n_tasks)

The training input samples. For each data slice, a clone estimator is fitted independently. The feature dimension can be multidimensional e.g. X.shape = (n_samples, n_features_1, n_features_2, n_tasks).

yarray, shape (n_samples,) | (n_samples, n_targets)

The target values.

**fit_paramsdict of str -> object

Parameters to pass to the fit method of the estimator.

Returns:
selfobject

Return self.

Examples using fit:

Decoding (MVPA)

Decoding (MVPA)

Decoding source space data

Decoding source space data

Decoding sensor space data with generalization across time and conditions

Decoding sensor space data with generalization across time and conditions
fit_transform(X, y, **fit_params)[source]#

Fit and transform a series of independent estimators to the dataset.

Parameters:
Xarray, shape (n_samples, nd_features, n_tasks)

The training input samples. For each task, a clone estimator is fitted independently. The feature dimension can be multidimensional, e.g.:

X.shape = (n_samples, n_features_1, n_features_2, n_estimators)
yarray, shape (n_samples,) | (n_samples, n_targets)

The target values.

**fit_paramsdict of str -> object

Parameters to pass to the fit method of the estimator.

Returns:
y_predarray, shape (n_samples, n_tasks) | (n_samples, n_tasks, n_targets)

The predicted values for each estimator.

get_metadata_routing()[source]#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

predict(X)[source]#

Predict each data slice/task with a series of independent estimators.

The number of tasks in X should match the number of tasks/estimators given at fit time.

Parameters:
Xarray, shape (n_samples, nd_features, n_tasks)

The input samples. For each data slice, the corresponding estimator makes the sample predictions, e.g.: [estimators[ii].predict(X[..., ii]) for ii in range(n_estimators)]. The feature dimension can be multidimensional e.g. X.shape = (n_samples, n_features_1, n_features_2, n_tasks).

Returns:
y_predarray, shape (n_samples, n_estimators) | (n_samples, n_tasks, n_targets)

Predicted values for each estimator/data slice.

predict_proba(X)[source]#

Predict each data slice with a series of independent estimators.

The number of tasks in X should match the number of tasks/estimators given at fit time.

Parameters:
Xarray, shape (n_samples, nd_features, n_tasks)

The input samples. For each data slice, the corresponding estimator makes the sample probabilistic predictions, e.g.: [estimators[ii].predict_proba(X[..., ii]) for ii in range(n_estimators)]. The feature dimension can be multidimensional e.g. X.shape = (n_samples, n_features_1, n_features_2, n_tasks).

Returns:
y_predarray, shape (n_samples, n_tasks, n_classes)

Predicted probabilities for each estimator/data slice/task.

score(X, y)[source]#

Score each estimator on each task.

The number of tasks in X should match the number of tasks/estimators given at fit time, i.e. we need X.shape[-1] == len(self.estimators_).

Parameters:
Xarray, shape (n_samples, nd_features, n_tasks)

The input samples. For each data slice, the corresponding estimator scores the prediction, e.g.: [estimators[ii].score(X[..., ii], y) for ii in range(n_estimators)]. The feature dimension can be multidimensional e.g. X.shape = (n_samples, n_features_1, n_features_2, n_tasks).

yarray, shape (n_samples,) | (n_samples, n_targets)

The target values.

Returns:
scorearray, shape (n_samples, n_estimators)

Score for each estimator/task.

Examples using score:

Decoding sensor space data with generalization across time and conditions

Decoding sensor space data with generalization across time and conditions
set_output(*, transform=None)[source]#

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters:
transform{“default”, “pandas”, “polars”}, default=None

Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • “polars”: Polars output

  • None: Transform configuration is unchanged

New in v1.4: “polars” option was added.

Returns:
selfestimator instance

Estimator instance.

set_params(**params)[source]#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

transform(X)[source]#

Transform each data slice/task with a series of independent estimators.

The number of tasks in X should match the number of tasks/estimators given at fit time.

Parameters:
Xarray, shape (n_samples, nd_features, n_tasks)

The input samples. For each data slice/task, the corresponding estimator makes a transformation of the data, e.g. [estimators[ii].transform(X[..., ii]) for ii in range(n_estimators)]. The feature dimension can be multidimensional e.g. X.shape = (n_samples, n_features_1, n_features_2, n_tasks).

Returns:
Xtarray, shape (n_samples, n_estimators)

The transformed values generated by each estimator.

Examples using mne.decoding.SlidingEstimator#

Decoding (MVPA)

Decoding (MVPA)

Decoding source space data

Decoding source space data

Decoding sensor space data with generalization across time and conditions

Decoding sensor space data with generalization across time and conditions