pyeeg.cca.CCA_Estimator.fit

CCA_Estimator.fit(X, y, cca_implementation='nt', thresh_x=None, normalise=True, thresh_y=None, n_comp=2, knee_point=None, drop=True, y_already_dropped=False, lag_y=False, ylags=(0.0,), feat_names=(), opt_cca_svd={})

Fit the CCA model.

Parameters:
  • X (ndarray (nsamples x nfeats)) – Array of features (time-lagged or not, if it is, then second dim’s shape should be nfeats*nlags). If drop=True the lag matrix is built internally from self.xlags.

  • y (ndarray (nsamples x nchans) or list of ndarray) – EEG data. If a list, each element must have the same number of samples; a generic (concatenated) CCA is then computed.

  • cca_implementation ({'nt', 'svd', 'sklearn'}, default: 'nt') –

    Which CCA backend to use:

    • 'nt': eigendecomposition-based CCA (cca_nt()).

    • 'svd': SVD-based CCA (cca_svd()), with the regularisation options given in opt_cca_svd.

    • 'sklearn': CCA from scikit-learn (CCA), keeping n_comp components.

  • thresh_x (float or None, default: None) – Variance-explained threshold used to whiten (sphere) X in the 'nt' implementation. If None, defaults to 0.999 (or to thresh_y when that is provided).

  • normalise (bool, default: True) – Reserved for normalising the data before fitting; currently unused by the implementation.

  • thresh_y (float or None, default: None) – Variance-explained threshold used to whiten (sphere) y in the 'nt' implementation. If None, defaults to thresh_x.

  • n_comp (int, default: 2) – Number of canonical components to keep when cca_implementation='sklearn'.

  • knee_point (bool or None, default: None) – If not None, knee-point (elbow) detection is applied on the eigenvalue curves before thresholding in the 'nt' implementation (see pyeeg.utils.find_knee_point()).

  • drop (bool, default: True) – Whether to drop non-valid samples when building the lag matrix (if False, non-valid samples are filled with 0.).

  • y_already_dropped (bool, default: False) – Whether the rows of y corresponding to non-valid samples have already been dropped. Only used when drop=True.

  • lag_y (bool, default: False) – Whether to also time-lag y (using ylags) before fitting. When True, self.ylags and self.ytimes are set.

  • ylags (tuple or 1d-array of float, default: (0.0,)) – Lag times (in seconds) at which y is lagged when lag_y=True.

  • feat_names (list of str, default: ()) – Names of each feature. If provided (non-empty), stored in self.feat_names_.

  • opt_cca_svd (dict, default: {}) – Regularisation options passed to cca_svd() when cca_implementation='svd'. Keys 'x' and 'y' hold per-block options (see reg_eigen()).

Returns:

self – The fitted estimator. Fit results are stored as attributes: intercept_, coefStim_, coefResponse_, score_, eigvals_x, eigvals_y, n_feats_ and n_chans_.

Return type:

CCA_Estimator

Notes

The lagged feature matrix X (and y when lag_y=True) is saved to a temporary file and its path stored in self.tempX_path_ / self.tempy_path_ so it can be reused by transform() and the plotting helpers without keeping the full data in memory.