Package: sleepens
Sleep EnsembleSleep Ensemble is a framework for end-to-end sleep state classification using machine learning. It is designed to allow for modular data processing, classification, and further post-processing.
Published inSLEEP.InstallationInstall a suitable python environment frompython.org.Sleep Ensemble supports Python 3.7 only. It is extensively tested and developed with 64-bit Python 3.7.8 on Windows.Sleep Ensemble pre-trained builds are only useable for the specific OS and 32/64-bit Python environment. The included pre-trained SleepEnsemble4 is built on 64-bit Python 3.7.8 on Windows.Install the latestsleepensrelease usingpip(on a terminal like command prompt):pip install sleepensAlternatively, download the source code for the latest releasehere. Unzip into desired location. Using the terminal, navigate to the topsleepensfolder wheresetup.pyis located and run the following:python setup.py installDownload any pre-trained buildshereor train your own.UsageSleep Ensemble is built for easy use with a text-based python script that you can run in a command terminal. This application allows you to quickly classify data or train new models.The application runs viasleepens.pywhich can be copied/moved anywhere as needed. To run, using the terminal, navigate tosleepens.pyand run:python sleepens.pyAs a framework, the Sleep Ensemble package can be used as you would any other package. The end-user program can be accessed:importsleepenssleepens.run()Alongside the Sleep Ensemble application, the framework is designed for high modularity and integration with other scripts in very little code.# Setup a protocolfromsleepens.protocols.sleepens4importSleepEnsemble4model=SleepEnsemble4()# Load a pre-trained model in a .joblib fileimportjoblibmodel.classifier=joblib.load("/path/to/model.joblib")# Classify your data# Data is a list of 2D arrays in the form of (n samples, n features)predictions=model.predict(data)For full details on usage, see thedocumentation.ChangelogSee thechangelogfor a history of notable changes tosleepens.Developmentsleepensis in a relatively finished state. It has not been tested on different Python environment and OS combinations.Currently,sleepenssupports .mat, .smr/.smrx, .xls file formats for reading and writing. Of note, presently the SONpy interface for reading/writing .smr/.smrx files works for reading .smr only and writing .smrx only. No clear documentation exists to explain errors when attempting to read from .smrx. Additional i/o interfaces can be contributed tosleepens.io.interfacesfollowing the basic structure.The underlying data processing pipelines and classification models are modular and can be adjusted to create different sleep ensemble models.sleepenscurrently contains one protocol, SleepEnsemble4, for 4-state sleep classification. New or modified protocols can be contributed tosleepens.protocolsfollowing the basic structure.Finally,sleepensusesjoblibto store the pre-trained builds. This isn't the most secure method nor is the most data storage efficient. Ideally, a custom parameter export/load method is implemented that can reinstate a pre-trained build.Dependenciessleepenswas developed using Python 3.7.8. Since development,scikit-learnhas updated to a point thatsleepensis not compatible with later versions ofscikit-learndue to attribute name changes. At the same time,sonpyis limited to Python 3.7 to 3.9. For the sake of replicability (especially with pre-trained models provided on publication, the repository remains using the below dependencies at these versions. This also limits Python to 3.7.numpy==1.21.6
scikit-learn==0.24.0
joblib==1.0.0
tqdm==4.55.0
xlrd==2.0.1
xlwt==1.3.0
sonpy==1.7.5
scipy==1.7.2Should one wish to upgrade these dependencies to the latest version ofscikit-learn, change all references ofn_features_ton_features_in_in the following:sleepens/sleepens/ml/_base_model.pysleepens/sleepens/ml/models/_gb.pysleepens/sleepens/ml/models/_tsens.pysleepens/sleepens/ml/models/_stsens.pyFurthermore, change the loss parameter insleepens/sleepens/ml/_gb.pyline 220 to 'log_loss' (which replaces 'deviance' but is algorithmically the same).Help and SupportDocumentationDocumentation forsleepenscan be foundhere.Issues and QuestionsIssues and Questions should be posed to the issue trackerhere.