MCPcopy Index your code
hub / github.com/mne-tools/mne-python / fit

Method fit

mne/decoding/base.py:514–553  ·  view source on GitHub ↗

Estimate the coefficients of the linear model. Save the coefficients in the attribute ``filters_`` and computes the attribute ``patterns_``. Parameters ---------- X : array, shape (n_samples, n_features) The training input samples to estimate the

(self, X, y, **fit_params)

Source from the content-addressed store, hash-verified

512 pass
513
514 def fit(self, X, y, **fit_params):
515 """Estimate the coefficients of the linear model.
516
517 Save the coefficients in the attribute ``filters_`` and
518 computes the attribute ``patterns_``.
519
520 Parameters
521 ----------
522 X : array, shape (n_samples, n_features)
523 The training input samples to estimate the linear coefficients.
524 y : array, shape (n_samples, [n_targets])
525 The target values.
526 **fit_params : dict of string -> object
527 Parameters to pass to the fit method of the estimator.
528
529 Returns
530 -------
531 self : instance of LinearModel
532 Returns the modified instance.
533 """
534 self._validate_params(X)
535 X, y = validate_data(self, X, y, multi_output=True)
536
537 # fit the Model
538 self.model_ = (
539 clone(self.model)
540 if self.model is not None
541 else LogisticRegression(solver="liblinear")
542 )
543 self.model_.fit(X, y, **fit_params)
544
545 # Computes patterns using Haufe's trick: A = Cov_X . W . Precision_Y
546 inv_Y = 1.0
547 X = X - X.mean(0, keepdims=True)
548 if y.ndim == 2 and y.shape[1] != 1:
549 y = y - y.mean(0, keepdims=True)
550 inv_Y = np.linalg.pinv(np.cov(y.T))
551 self.patterns_ = np.cov(X.T).dot(self.filters_.T.dot(inv_Y)).T
552
553 return self
554
555 @property
556 def filters_(self):

Callers 5

_fit_transformMethod · 0.95
test_get_coef_multiclassFunction · 0.95
test_linearmodelFunction · 0.95
test_spatial_filter_initFunction · 0.95
_fit_and_scoreFunction · 0.45

Calls 3

_validate_paramsMethod · 0.95
validate_dataFunction · 0.85
meanMethod · 0.45

Tested by 3

test_get_coef_multiclassFunction · 0.76
test_linearmodelFunction · 0.76
test_spatial_filter_initFunction · 0.76