Decoder¶
- class Decoder(categories: dict, n_splits: int = 5, n_repeats: int = 1, min_samples: int = 1, which: str = 'test', **kwargs)[source][source]¶
-
- cv_cm(x_data: Any, labels: Any, normalize: str = None, obs_axs: int = -2, n_jobs: int = 1, average_repetitions: bool = True, window: int = None, shuffle: bool = False, oversample: bool = True, step: int = 1) Any[source][source]¶
Cross-validated confusion matrix
- Parameters:
x_data (
np.ndarray) – The data to be decodedlabels (
np.ndarray) – The labels for the datanormalize (
str, optional) – How to normalize the confusion matrix, by default Noneobs_axs (
int, optional) – The axis containing the observations, by default -2n_jobs (
int, optional) – The number of jobs to run in parallel, by default 1average_repetitions (
bool, optional) – Whether to average the repetitions, by default Truewindow (
int, optional) – The window size for time sliding, by default Noneshuffle (
bool, optional) – Whether to shuffle the labels, by default Falseoversample (
bool, optional) – Whether to oversample the training data, by default Truestep (
int, optional) – The step size for time sliding, by default 1
- Returns:
The confusion matrix
- Return type:
np.ndarray
Examples
>>> np.random.seed(42) >>> decoder = Decoder({'heat': 1, 'hoot': 2, 'hot': 3, 'hut': 4}, ... 5, 10, explained_variance=0.8, da_type='lda') >>> X = np.random.randn(100, 50, 100) >>> labels = np.random.randint(1, 5, 50) >>> decoder.cv_cm(X, labels, normalize='true') array([[0.11111111, 0. , 0.03333333, 0.85555556], [0.1 , 0. , 0.04 , 0.86 ], [0.10666667, 0. , 0.04 , 0.85333333], [0.10625 , 0. , 0.03125 , 0.8625 ]]) >>> decoder = Decoder({'heat': 1, 'hoot': 2, 'hot': 3, 'hut': 4}, ... 5, 10, explained_variance=0.8, da_type='lda') >>> decoder.cv_cm(X, labels, normalize='true', window=20, step=5)[0] array([[0.04444444, 0. , 0.36666667, 0.58888889], [0.02 , 0.01 , 0.41 , 0.56 ], [0.03333333, 0. , 0.50666667, 0.46 ], [0.03125 , 0. , 0.5 , 0.46875 ]]) >>> decoder.cv_cm(X, labels, normalize='true', window=20, step=5, ... shuffle=True, oversample=True)[0] array([[0. , 0.12222222, 0.52222222, 0.35555556], [0.01 , 0.12 , 0.5 , 0.37 ], [0.00666667, 0.10666667, 0.50666667, 0.38 ], [0. , 0.09375 , 0.525 , 0.38125 ]]) >>> import cupy as cp >>> X = cp.random.randn(100, 100, 50, 100) >>> X[0, 0, 0, :] = np.nan >>> labels = cp.random.randint(1, 5, 50) >>> with config_context(array_api_dispatch=True): ... decoder.cv_cm(X, labels, normalize='true') array([[0. , 0.36666667, 0.63333333, 0. ], [0. , 0.32777778, 0.67222222, 0. ], [0. , 0.33157895, 0.66842105, 0. ], [0. , 0.35714286, 0.64285714, 0. ]])