[Mne_analysis] ConfoundRegressor with GeneralizingEstimator {Disarmed}

Giulia Gennari giulia.gennari1991 at gmail.com
Wed Nov 18 13:51:21 EST 2020
Search archives:

        External Email - Use Caution        

Hello,

I would like to check whether, once the influence of some confound
variables is ruled out, my decoding still works (EEG data).
To do so, I thought to try the cross-validated "confound regression"
described in this paper
<https://secure-web.cisco.com/1ni3y8J6xZXcf5o3KPFNk6U313fE6N5vcmAuJGOmJTv98GdPW9u0zZEhdh-kXMyZZ5LlCEAw6ZvbwnMX36hp_DICC616sLn7tvjNXHVIzktFf4ZnMJlFrUBVncwY28FroSoWwBckoj8atB8RQQtcq5uKv5Tlh5k9oVblcxyVUmX43jj4mctL48Xo862JphSPO7q2rj2Wul6NCLrz_PTpOHk5MedEbub_IgdZhWrVSjVlDCaOD8ONU2nq4-Kagp0CWmPk3b2vrKwh5OtkW_phc5Q/https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS1053811918319463>. The
code for that is in Github:
https://secure-web.cisco.com/1iLimRkNJpKP4OGM7F90HkY2QAK_g2Q_tcxxWfAVgh1PWR0zMBdJRD8ipMG4YL_twA8YjtkR72AAHd64-9qVJnjG3ulxd6eOPGqMv3MLQxBYWh8Hd5HflxbvYFS6DTe7b2ixDBnj685cgTQBWFHWITu7jF2ycfq0l6nmUlSNkb9Sl1GyQ4akYkOynxpjIBEYz0OnBbXCECZlH4oh7vkIFcbOC3RS6IVzLymk9YOhHl02iW03x91wuKfg9jrZcCtxhbChHpLHW2OZPNyZFvehhOQ/https%3A%2F%2Fgithub.com%2Flukassnoek%2FMVCA%2Fblob%2Fmaster%2Fanalyses%2Fconfounds.py

The ConfoundRegressor works when I select just one time point, e.g. :

temp_data = epochs_train.get_data()
temp_c = epochs_train.metadata.values

cfr = ConfoundRegressor(confound=temp_c, X=temp_data[:,:,100])
X_train_corr = cfr.fit_transform(temp_data[:,:,100])

However, when I try to insert it in the slider I don't manage to make it
work:
cfr = ConfoundRegressor(confound=temp_c, X=temp_data)
confound_slider = GeneralizingEstimator(cfr)
epochs_train_corr = confound_slider.fit_transform(temp_data, y=None)


IndexError                                Traceback (most recent call last)
/neurospin/grip/protocols/EEG/Giulia_NUM_MUSIK/TRY_confound_regressor.py in
<mod                 ule>
    210 confound_slider = GeneralizingEstimator(cfr)
    211
--> 212 epochs_train_corr = confound_slider.fit_transform(temp_data, y=None)
    213
    214

~/anaconda3/lib/python3.8/site-packages/mne/decoding/search_light.py in
fit_tran                 sform(self, X, y, **fit_params)
    127             The predicted values for each estimator.
    128         """  # noqa: E501
--> 129         return self.fit(X, y, **fit_params).transform(X)
    130
    131     @verbose  # to use the class value

<decorator-gen-407> in fit(self, X, y, **fit_params)

~/anaconda3/lib/python3.8/site-packages/mne/decoding/search_light.py in
fit(self                 , X, y, **fit_params)
     91         mesg = 'Fitting %s' % (self.__class__.__name__,)
     92         with ProgressBar(X.shape[-1], mesg=mesg) as pb:
---> 93             estimators = parallel(
     94                 p_func(self.base_estimator, split, y,
pb.subset(pb_idx),
     95                        **fit_params)

~/anaconda3/lib/python3.8/site-packages/mne/decoding/search_light.py in
<genexpr                 >(.0)
     92         with ProgressBar(X.shape[-1], mesg=mesg) as pb:
     93             estimators = parallel(
---> 94                 p_func(self.base_estimator, split, y,
pb.subset(pb_idx),
     95                        **fit_params)
     96                 for pb_idx, split in array_split_idx(X, n_jobs,
axis=-1)                 )

~/anaconda3/lib/python3.8/site-packages/mne/decoding/search_light.py in
_sl_fit(                 estimator, X, y, pb, **fit_params)
    330     for ii in range(X.shape[-1]):
    331         est = clone(estimator)
--> 332         est.fit(X[..., ii], y, **fit_params)
    333         estimators_.append(est)
    334         pb.update(ii + 1)

/neurospin/grip/protocols/EEG/Giulia_NUM_MUSIK/confounds.py in fit(self
            , X, y)
     84             self.X = self.X[:, self.nonzero_X_]
     85
---> 86         X_nz = X[:, self.nonzero_X_]
     87         confound = self.confound
     88

IndexError: too many indices for array: array is 2-dimensional, but 3 were
indexed

Little help? Would you know what this error is related to?

Thank you, in advance.

Giulia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20201118/e9f13017/attachment.html 


More information about the Mne_analysis mailing list