Package: pyriemann
pyRiemannpyRiemann is a Python machine learning package based onscikit-learnAPI.
It provides a high-level interface for processing and classification of multivariate time series
through the Riemannian geometry of symmetric positive definite (SPD) matrices.pyRiemann aims at being a generic package for multivariate time series classification
but has been designed around multichannel biosignals (like EEG, MEG or EMG) manipulation applied to brain-computer interface (BCI),
transforming multichannel time series into covariance matrices, and classifying them using the Riemannian geometry of SPD matrices[1].For BCI applications, studied paradigms are motor imagery[2][3], event-related potentials (ERP)[4]and steady-state visually evoked potentials (SSVEP)[5].
Using extended labels, API allows transfer learning between sessions or subjects[6].This code is BSD-licenced (3 clause).DocumentationThe documentation is available onhttp://pyriemann.readthedocs.io/en/latest/InstallUsing PyPIpip install pyriemannor using pip+git for the latest version of the code :pip install git+https://github.com/pyRiemann/pyRiemannUsing condaThe package is distributed viaconda-forge.
You could install it in your working environment, with the following command:condainstall-cconda-forgepyriemannFrom sourcesFor the latest version, you can install the package from the sources usingpip:pipinstall.or in editable mode to be able to modify the sources:pipinstall-e.How to use itMost 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 the MDM algorithm described in[2], it is easy as:importpyriemannfromsklearn.model_selectionimportcross_val_score# load your dataX=...# EEG data, in format n_epochs x n_channels x n_timesy=...# labels# estimate covariance matricescov=pyriemann.estimation.Covariances().fit_transform(X)# cross validationmdm=pyriemann.classification.MDM()accuracy=cross_val_score(mdm,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[3]:frompyriemann.estimationimportCovariancesfrompyriemann.tangentspaceimportTangentSpacefromsklearn.pipelineimportmake_pipelinefromsklearn.svmimportSVCfromsklearn.model_selectionimportcross_val_score# load your dataX=...# EEG data, in format n_epochs x n_channels x n_timesy=...# labels# build your pipelinecovest=Covariances()ts=TangentSpace()svc=SVC(kernel='linear')clf=make_pipeline(covest,ts,svc)# cross validationaccuracy=cross_val_score(clf,X,y)print(accuracy.mean())Check out the example folder for more examples !Contribution GuidelinesThe package aims at adopting thescikit-learnandMNE-Pythonconventions as much as possible.
See their contribution guidelines before contributing to the repository.TestingIf you make a modification, run the test suite before submitting a pull requestpytestHow to cite@software{pyriemann,author={Alexandre Barachant andQuentin Barthélemy andJean-Rémi King andAlexandre Gramfort andSylvain Chevallier andPedro L. C. Rodrigues andEmanuele Olivetti andVladislav Goncharenko andGabriel Wagner vom Berg andGhiles Reguig andArthur Lebeurrier andErik Bjäreholt andMaria Sayu Yamamoto andPierre Clisson andMarie-Constance Corsi},title={pyRiemann/pyRiemann: v0.3},month=jul,year=2022,publisher={Zenodo},version={v0.3},doi={10.5281/zenodo.7547583},url={https://doi.org/10.5281/zenodo.7547583}}References[1]M. Congedo, A. Barachant and R. Bhatia, "Riemannian geometry for EEG-based brain-computer interfaces; a primer and a review".
Brain-Computer Interfaces, 4.3, pp. 155-174, 2017.link[2]A. Barachant, S. Bonnet, M. Congedo and C. Jutten, "Multiclass Brain-Computer Interface Classification by Riemannian Geometry".
IEEE Transactions on Biomedical Engineering, vol. 59, no. 4, pp. 920-928, 2012.link[3]A. Barachant, S. Bonnet, M. Congedo and C. Jutten, "Classification of covariance matrices using a Riemannian-based kernel for BCI applications".
Neurocomputing, 112, pp. 172-178, 2013.link[4]A. Barachant and M. Congedo, "A Plug&Play P300 BCI Using Information Geometry".
Research report, 2014.link[5]EK. Kalunga, S. Chevallier, Q. Barthélemy, K. Djouani, E. Monacelli and Y. Hamam, "Online SSVEP-based BCI using Riemannian geometry".
Neurocomputing, 191, pp. 55-68, 2014.link[6]PLC. Rodrigues, C. Jutten and M. Congedo, "Riemannian Procrustes analysis: transfer learning for brain-computer interfaces".
IEEE Transactions on Biomedical Engineering, vol. 66, no. 8, pp. 2390-2401, 2018.link