Predicting with CSP for motor imagery

  • MNE version: e.g. 1.3.0
  • operating system: Ubuntu 20.04

Hello everyone!

I am trying to train a model that detects in (relatively) real time motor imagery.

I used the following example code for training with my own EEG data (Motor imagery decoding from EEG data using the Common Spatial Pattern (CSP) — MNE 1.4.dev0 documentation) and I was successfully able to train the model. After that I saved the trained model with pickle5.

My idea is to create a script that loads the model, receives a fif with new measurement and correctly classify the motor imagery. The problem is that I am not able to predict with the model.

Some extra information (where the problem may be):

  • Measurements are 5 seconds intercalating “trigger” and “relax” measurements.
  • I manually annotated them with a single label for the whole length of each measurement (5 seconds) with either “trigger” or “relax” label.

Any suggestion how to solve this?. Thanks in advance!

Hi,

I am not quite sure what you mean when you say “I am not able to predict”, but I suppose you mean that the prediction is bad, that is, you have a classification accuracy around the expected chance level.

If that is the case, my first step would be to train a second model on part of the new data and test it with a small subset of these (and possibly as a next step also test with the original training data). If that works better, it just means that your first model can’t generalize on whatever new data you provide to it. It’s fairly common for data from different blocks or sessions not to aligne, thus making the ability to generalize tricky. This is why many BCI paradigms rely on calibration blocks of trials before proceeding with online decoding of new data.

If not, it still may be the case that the new data are just too difficult to make sense of, but I would try using a completely different dataset in order to debug (just to be sure the data are the cause of the problem, not the script).

Returning back to your own data, maybe you need a different/better hypothesis on whatever features should be differentiating between the two conditions. You could, for example, vary the band pass filtering or use a filter bank approach in the initial phase of your algorithm, or even try a non-linear classifier (albeit I doubt it would change much).