pyeeg.models.TRFEstimator.xfit
- TRFEstimator.xfit(X, y, n_splits=5, lagged=False, drop=True, feat_names=(), plot=False, verbose=False)
Apply a cross-validation procedure to find the best regularisation parameters among the list of alphas given (ndim alpha must be == 1, and len(alphas)>1). If there are several subjects, will return a list of best alphas for each subjetc individually. User is expected to re-fit TRF fr each subject using their best individual alpha.
For a single subject (y is 2-dimensional), the TRF stored is the one with best alpha.
- Parameters:
X (ndarray (nsamples, nfeats)) – Array of features (time-lagged or not). If not lagged, the second dimension must be
nfeats; if already lagged, it must benfeats * nlags.y (ndarray) – EEG data, shape (nsamples, nchans) for a single subject or (nsubjects, nsamples, nchans) for several subjects.
n_splits (int) – Number of K-fold splits to use for cross-validation. Default: 5.
lagged (bool) – Whether the
Xmatrix has been previously lagged. Default: False.drop (bool) – Whether to drop non-valid samples (if False, non-valid samples are filled with 0.). Default: True.
feat_names (list) – Names of features being fitted. Must be of length
nfeats.plot (bool) – Whether to plot the score against the different alphas. Default: False.
verbose (bool) – Whether to log progress information. Default: False.
- Returns:
scores (ndarray) – Cross-validation scores, shape (n_splits, n_subjects_or_1, n_alphas, n_chans).
best_alphas (ndarray or float) – Best regularisation value found for each subject. A 1d-array (one per subject) when
yis 3-dimensional, or a float for a single subject.
Notes
The cross-validation procedure is a simple K-fold procedure with shuffling of samples. This is prone to some leakage since lags span several contiguous samples…