mne.decoding.Scaler#
- class mne.decoding.Scaler(info=None, scalings=None, with_mean=True, with_std=True)[source]#
Standardize channel data.
This class scales data for each channel. It differs from scikit-learn classes (e.g.,
sklearn.preprocessing.StandardScaler
) in that it scales each channel by estimating μ and σ using data from all time points and epochs, as opposed to standardizing each feature (i.e., each time point for each channel) by estimating using μ and σ using data from all epochs.- Parameters:
- info
mne.Info
|None
The
mne.Info
object with information about the sensors and methods of measurement. Only necessary ifscalings
is a dict or None.- scalings
dict
,str
, defaultNone
Scaling method to be applied to data channel wise.
if scalings is None (default), scales mag by 1e15, grad by 1e13, and eeg by 1e6.
if scalings is
dict
, keys are channel types and values are scale factors.if
scalings=='median'
,sklearn.preprocessing.RobustScaler
is used (requires sklearn version 0.17+).if
scalings=='mean'
,sklearn.preprocessing.StandardScaler
is used.
- with_meanbool, default
True
If True, center the data using mean (or median) before scaling. Ignored for channel-type scaling.
- with_stdbool, default
True
If True, scale the data to unit variance (
scalings='mean'
), quantile range (scalings='median
), or using channel type ifscalings
is a dict or None).
- info
Methods
fit
(epochs_data[, y])Standardize data across channels.
fit_transform
(epochs_data[, y])Fit to data, then transform it.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
inverse_transform
(epochs_data)Invert standardization of data across channels.
set_fit_request
(*[, epochs_data])Configure whether metadata should be requested to be passed to the
fit
method.set_inverse_transform_request
(*[, epochs_data])Configure whether metadata should be requested to be passed to the
inverse_transform
method.set_output
(*[, transform])Set output container.
set_params
(**params)Set the parameters of this estimator.
set_transform_request
(*[, epochs_data])Configure whether metadata should be requested to be passed to the
transform
method.transform
(epochs_data)Standardize data across channels.
- fit_transform(epochs_data, y=None)[source]#
Fit to data, then transform it.
Fits transformer to epochs_data and y and returns a transformed version of epochs_data.
- Parameters:
- Returns:
- X
array
, shape (n_epochs, n_channels, n_times) The data concatenated over channels.
- X
Notes
This function makes a copy of the data before the operations and the memory usage may be large with big data.
- get_metadata_routing()[source]#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routing
MetadataRequest
A
MetadataRequest
encapsulating routing information.
- routing
- inverse_transform(epochs_data)[source]#
Invert standardization of data across channels.
- Parameters:
- epochs_dataarray, shape ([n_epochs, ]n_channels, n_times)
The data.
- Returns:
- X
array
, shape (n_epochs, n_channels, n_times) The data concatenated over channels.
- X
Notes
This function makes a copy of the data before the operations and the memory usage may be large with big data.
- set_fit_request(*, epochs_data: bool | None | str = '$UNCHANGED$') Scaler [source]#
Configure whether metadata should be requested to be passed to the
fit
method.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config()
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in v1.3.
- set_inverse_transform_request(*, epochs_data: bool | None | str = '$UNCHANGED$') Scaler [source]#
Configure whether metadata should be requested to be passed to the
inverse_transform
method.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config()
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toinverse_transform
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toinverse_transform
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in v1.3.
- 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
andfit_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:
- self
estimator
instance Estimator instance.
- self
- 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.
- set_transform_request(*, epochs_data: bool | None | str = '$UNCHANGED$') Scaler [source]#
Configure whether metadata should be requested to be passed to the
transform
method.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config()
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed totransform
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it totransform
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in v1.3.
- transform(epochs_data)[source]#
Standardize data across channels.
- Parameters:
- epochs_data
array
, shape (n_epochs, n_channels[, n_times]) The data.
- epochs_data
- Returns:
- X
array
, shape (n_epochs, n_channels, n_times) The data concatenated over channels.
- X
Notes
This function makes a copy of the data before the operations and the memory usage may be large with big data.