eelbrain.ChannelModel

class eelbrain.ChannelModel(model='huber', alpha=0.0001, epsilon=1.35, fit_intercept=True, **kwargs)[source]

Regression model predicting each sensor from the other sensors.

A separate regression model is fit for each sensor, predicting that sensor’s signal from all the other sensors. This can be used to reconstruct (e.g. interpolate) channels with predict(), or to identify bad channels with score().

Parameters:
  • model (str | BaseEstimator) – The regression model to use for each sensor. 'huber' (default) uses sklearn.linear_model.HuberRegressor, which is robust to high-amplitude artifacts in the training data while also regularizing collinear channels through alpha. 'ridge' uses sklearn.linear_model.Ridge (fast, but artifacts in the training data bias the fit). 'ols' uses ordinary least squares (sklearn.linear_model.LinearRegression). Alternatively, any scikit-learn estimator instance can be passed and is cloned for each sensor (in which case the other parameters are ignored).

  • alpha (float) – L2 regularization strength ('huber' and 'ridge' only). Features and target are robustly scaled before fitting (see Notes), so alpha applies in a unit-scale space and is independent of the data amplitude.

  • epsilon (float) – Huber threshold: residuals smaller than this are treated with squared loss (OLS-like), larger ones with linear loss (robust). The smaller the value, the more robust to outliers ('huber' only).

  • fit_intercept (bool) – Estimate an intercept for each sensor (default True).

  • ... – Additional keyword arguments are passed to the estimator.

Notes

Before fitting, the predictor channels and the target channel are each scaled with sklearn.preprocessing.RobustScaler (centered on the median, scaled by the inter-quartile range). This makes the fit invariant to the overall data amplitude (EEG in volts is ~1e-6, which otherwise makes regularized/robust estimators like 'huber' collapse to flat predictions) and prevents high-amplitude artifacts from inflating the scaling. The scaling is inverted automatically, so predictions are returned in the original units.

sensor

The sensor dimension the model was fit with.

Type:

eelbrain._data_obj.Sensor

estimators_

The fitted estimator for each sensor (in the order of sensor).

Type:

list

Methods

find_bad_windows(data[, threshold, ...])

Find the time windows in which each sensor is bad.

fit(data[, threshold])

Fit the model.

predict(data)

Predict each sensor from the other sensors.

score(data[, threshold, max_exclude])

Score each sensor by how badly it is predicted from the others.