# Question about spatial patterns using LinearModel()	and cross-validation

**URL:** <https://mne.discourse.group/t/question-about-spatial-patterns-using-linearmodel-and-cross-validation/1405>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [January 24, 2018, 4:15pm UTC](https://mne.discourse.group/t/question-about-spatial-patterns-using-linearmodel-and-cross-validation/1405 "2018-01-24T16:15:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 24, 2018, 4:15pm UTC](https://mne.discourse.group/t/question-about-spatial-patterns-using-linearmodel-and-cross-validation/1405/1 "2018-01-24T16:15:03Z")

</div>

Dear all,

I am dealing with a classification problem (Linear SVMs) in EEG data. I am  
a new-comer in Python and also in the MNE community, so what I am going to  
ask might sound silly.

I am trying to estimate the patterns using the LinearModel and get\_coef().  
I was looking in the documentation (  
[http://martinos.org/mne/stable/auto\_examples/decoding/plot\_linear\_model\_patterns.html](http://martinos.org/mne/stable/auto_examples/decoding/plot_linear_model_patterns.html)),  
and saw that the LinearModel() class is not cross-validated. I was  
wondering it would make sense to retrieve cross-validated spatial patterns?

Thank you for your attention.

Best wishes,  
Ana Vedoveli  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20180124/2aa02f5c/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180124/2aa02f5c/attachment.html)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 24, 2018, 8:31pm UTC](https://mne.discourse.group/t/question-about-spatial-patterns-using-linearmodel-and-cross-validation/1405/2 "2018-01-24T20:31:50Z")

</div>

Hi Ana,

Indeed, in theory it's probably best to report the patterns that match the  
decoding scores, and thus use cross-validation:

e.g.

X=epochs.get\_data()  
y=epochs.events[:, 2]

pipeline = make\_pipeline(StandardScaler(), LogisticRegression())  
patterns = list()  
for train, test in cv.split(X, y):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lm = LinearModel(pipeline)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lm.fit(X, y)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pattern = get\_coef(lm, 'patterns\_')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;patterns.append(pattern)  
patterns= np.mean(patterns, axis=0)

However, in practice this CV is an overkill because the patterns (and  
spatial filters) correspond to the model, and thus depend on the training  
data. Since the training splits are not independent with one another, the  
patterns across splits should be very similar - and in fact converge  
towards the patterns of the non-cv fit.

Hope that helps

Jean-Remi
