pySTMM is a Python 3 package implementation for Support Tensor Machine Multiclassifier
The primary target is classification of multivariate biosignals (like EEG, MEG or EMG) Images, and Text.
This code is MIT-licenced.
The documentation is available on URL:
Linear decision function for binary Support Vector Machine on pattern x may be stated as:
Similarly, for pattern X:
Multiclassification is reached by OneVsRest, or OneVsOne heuristics.
pip3 install pystmm
or using pip+git for the latest version of the code :
pip3 install git+https://github.com/cdfbdex/pySTMM/pySTMM
Anaconda is not currently supported, if you want to use anaconda, you need to create a virtual environment in anaconda, activate it and use the above command to install it.
For the latest version, you can install the package from the sources using the setup.py script
python3 setup.py install
or in developer mode to be able to modify the sources.
python3 setup.py develop
Most of the functions mimic the scikit-learn API, and therefore can be directly used with sklearn. For example, for cross-validation classification of EEG signal using, it is easy as :
import pystmm
from sklearn.model_selection import cross_val_score
# load your data
X = ... # your EEG data, in format Ntrials x Nchannels X Nsamples
y = ... # the labels
# cross validation
clf = pystmm.classifiier.STMM()
accuracy = cross_val_score(clf, cov, y)
print(accuracy.mean())
You can also pipeline methods using sklearn Pipeline framework. For example, to classify EEG signal using a SVM classifier in the tangent space, described in [5] :
from pystmm.classifier import STMM
from sklearn.model_selection import cross_val_score
# load your data
X = ... # your EEG data, in format Ntrials x Nchannels X Nsamples
y = ... # the labels
stmm = STMM()
clf = make_pipeline(stmm)
# cross validation
accuracy = cross_val_score(clf, X, y)
print(accuracy.mean())
Check out the example folder for more examples !
The package aims at adopting the Scikit-Learn and MNE-Python conventions as much as possible. See their contribution guidelines before contributing to the repository.
[1] Carlos Ferrin-Bolaños, et.al., "Assessing the Contribution of Covariance Information to the Electroencephalographic Signals of Brain–Computer Interfaces for Spinal Cord Injury Patients ", Revista TecnoLógicas. 2019. DOI: link
- Add example on EEG Motor-Imagery classification
- Add example on Image classification
- Add example on Text Categorization
- Fix compatibility with scikit-learn v0.24