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=Truethe lag matrix is built internally fromself.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 inopt_cca_svd.'sklearn': CCA from scikit-learn (CCA), keepingn_compcomponents.
thresh_x (float or None, default: None) – Variance-explained threshold used to whiten (sphere)
Xin the'nt'implementation. If None, defaults to 0.999 (or tothresh_ywhen 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)
yin the'nt'implementation. If None, defaults tothresh_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 (seepyeeg.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
ycorresponding to non-valid samples have already been dropped. Only used whendrop=True.lag_y (bool, default: False) – Whether to also time-lag
y(usingylags) before fitting. When True,self.ylagsandself.ytimesare set.ylags (tuple or 1d-array of float, default: (0.0,)) – Lag times (in seconds) at which
yis lagged whenlag_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()whencca_implementation='svd'. Keys'x'and'y'hold per-block options (seereg_eigen()).
- Returns:
self – The fitted estimator. Fit results are stored as attributes:
intercept_,coefStim_,coefResponse_,score_,eigvals_x,eigvals_y,n_feats_andn_chans_.- Return type:
Notes
The lagged feature matrix
X(andywhenlag_y=True) is saved to a temporary file and its path stored inself.tempX_path_/self.tempy_path_so it can be reused bytransform()and the plotting helpers without keeping the full data in memory.