|
20 | 20 | labels. To interpret our model, labels can be organized in a graph of semantic |
21 | 21 | relashionship based on the `Wordnet <https://wordnet.princeton.edu/>`_ dataset. |
22 | 22 |
|
23 | | -*Summary:* We first concatenate the features with multiple delays, to account |
24 | | -for the slow hemodynamic response. We then fit a predictive model of BOLD |
25 | | -activity, using a linear regression that weights differently each delayed |
26 | | -feature. The linear regression is regularized to improve robustness to |
| 23 | +*Summary:* We first concatenate the features with multiple temporal delays, to |
| 24 | +account for the slow hemodynamic response. We then fit a predictive model of |
| 25 | +BOLD activity, using a linear regression that weighs each delayed feature |
| 26 | +differently. The linear regression is regularized to improve robustness to |
27 | 27 | correlated features and to improve generalization. The optimal regularization |
28 | 28 | hyperparameter is selected over a grid-search with cross-validation. Finally, |
29 | 29 | the model generalization performance is evaluated on a held-out test set, |
|
46 | 46 | # Load the data |
47 | 47 | # ------------- |
48 | 48 | # |
49 | | -# We first load the fMRI responses. |
| 49 | +# We first load the fMRI responses. These responses have been preprocessed as |
| 50 | +# decribed in [1]_. The data is separated into a training set ``Y_train`` and a |
| 51 | +# testing set ``Y_test``. The training set is used for fitting models, and |
| 52 | +# selecting the best models and hyperparameters. The testing set is later used |
| 53 | +# to estimate the generalization performances of the selected model. The |
| 54 | +# testing set contains multiple repetitions of the same experiment, to estimate |
| 55 | +# an upper bound of the model performances (cf. previous example). |
50 | 56 | import numpy as np |
51 | 57 | from voxelwise_tutorials.io import load_hdf5_array |
52 | 58 |
|
|
75 | 81 | Y_test = np.nan_to_num(Y_test) |
76 | 82 |
|
77 | 83 | ############################################################################### |
78 | | -# Then, we load the semantic "wordnet" features. |
| 84 | +# Then, we load the semantic "wordnet" features, extracted from the stimulus at |
| 85 | +# each time point. The features corresponding to the training set are noted |
| 86 | +# ``X_train``, and the features corresponding to the testing set are noted |
| 87 | +# ``X_test``. |
79 | 88 | feature_space = "wordnet" |
80 | 89 |
|
81 | 90 | file_name = os.path.join(directory, "features", f"{feature_space}.hdf") |
|
123 | 132 | # |
124 | 133 | # However, we prefer not to normalize by the standard deviation of each |
125 | 134 | # feature. Indeed, if the features are extracted in a consistent way from the |
126 | | -# stimulus, there relative scale is meaningful. Normalizing them independently |
| 135 | +# stimulus, their relative scale is meaningful. Normalizing them independently |
127 | 136 | # from each other would remove this meaning. Moreover, the wordnet features are |
128 | 137 | # one-hot-encoded, which means that each feature is either present (1) or not |
129 | 138 | # present (0) in each sample. Normalizing one-hot-encoded features is not |
|
225 | 234 | ############################################################################### |
226 | 235 | # We can display the ``scikit-learn`` pipeline with an HTML diagram. |
227 | 236 | from sklearn import set_config |
228 | | -set_config(display='diagram') |
| 237 | +set_config(display='diagram') # requires scikit-learn 0.23 |
229 | 238 | pipeline |
230 | 239 |
|
231 | 240 | ############################################################################### |
|
0 commit comments