timedecoder_utils module

timedecoder_utils.decode_time_step(X_i, y, y_dict, clf, scaler, n_splits=5, sampler=[], do_pca=False, n_components=0.95, permute_train_labels=False, compute_auc=False)

Run a classification of data X_i with labels y using a Stratified K-Folds cross-validation where n_splits is the number of folds. Classification pipeline, for each one of the Stratified K-Folds :

  1. If do_pca is True, first do a standardization scaling and then apply PCA and keep only the first n_components
  2. Apply the scaler. Fit the transform on the training set and apply it on the test set
  3. Resample the train set so that the train set is balanced between classes, using the sampler argument
  4. Train the classifier on the train set (If permute_train_labels is True, permute the training labels first)
  5. Predict labels on the test set
  6. Evaluate the performances with several scores

See also timedecoder.TimeDecoder.decode()

Parameters:
X_i : 2D array [n_features, n_trials]

Feature array

y : array [n_trials]

Label of each trial in X_i

y_dict : dict

Label dictionnary

clf : sklearn classifier

Scikit-Learn classifier

scaler : sklearn scaler

Scikit-Learn scaler

n_splits : int

Number of folds for the Stratified K-Folds cross-validation

sampler : sklearn sampler

Scikit learn sampler - see timedecoder.get_sampler()

do_pca : bool (default: False)

If True, apply a PCA decomposition and keep only a certain amount of components given n_components

n_components : int | float

Number of components to keep when running the PCA If 0 < n_components < 1 and svd_solver == 'full', select the number of components such that the amount of variance that needs to be explained is greater than the percentage specified by n_components.

permute_train_labels : bool (default: False)

If True, permute the training labels. Used for computing the chance level.

compute_auc : bool (default: False)

If True, will try to compute the Area Under the Curve score

Returns:
accuracy_mean : float

Accuracy, mean over the K-folds

f1_mean : float

F1-score, mean over the K-folds

precision_mean : float

Precision, mean over the K-folds

recall_mean : float

Recall, mean over the K-folds

class_acc_mean : array [n_classes]

Class-accuracy for each class, mean over the K-folds

auc_mean : float

Area under the curve, mean over the K-folds

timedecoder_utils.temporal_generalization_step(X, i_time, y, y_dict, clf, scaler, n_splits=5, sampler=[], do_pca=False, n_components=0.95, permute_train_labels=False)

Temporal generalization step. Train at time i_time and test for all time points. Use a stratified K-folds cross validation.

Pipeline, for each stratified K-folds:
  1. If do_pca is True, first do a standardization scaling and then apply PCA and keep only the first n_components on the train set
  2. Apply the scaler. Fit the transform on the training set
  3. Resample the train set so that the train set is balanced between classes, using the sampler argument
  4. Train the classifier on the train set (If permute_train_labels is True, permute the training labels first)
  5. For each time point :
  • If do_pca is True, do a standardization scaling and then apply PCA on the test set
  • Apply the scaler on the test set
  • Predict labels on the test set
  • Evaluate the performances with several scores

See also timedecoder.TimeDecoder.temporal_generalization()

Parameters:
X : 3D array [n_features, n_pnts, n_trials]

Temporal feature array

i_time : int

Training time point

y : array [n_trials]

Label array

y_dict : dict

Label dictionnary

clf : sklearn classifier

Scikit-Learn classifier

scaler : sklearn scaler

Scikit-Learn scaler

n_splits : int

Number of folds for the Stratified K-Folds cross-validation

sampler : sklearn sampler

Scikit learn sampler - see timedecoder.get_sampler()

do_pca : bool (default: False)

If True, apply a PCA decomposition and keep only a certain amount of components given n_components

n_components : int | float

Number of components to keep when running the PCA If 0 < n_components < 1 and svd_solver == 'full', select the number of components such that the amount of variance that needs to be explained is greater than the percentage specified by n_components.

permute_train_labels : bool (default: False)

If True, permute the training labels. Used for computing the chance level.

Returns:
accuracy_mean : float

Accuracy, mean over the K-folds

class_acc_mean : array [n_classes]

Class-accuracy for each class, mean over the K-folds