Dreem
Started on Jan. 1, 2019
The measurment of sleep is usually done in a sleep laboratory. Various electrods are attached to the head to measure physiological signals. Electrical activity in the brain is measured by electroencephalography (EEG). Muscle activity is recorded using electromyography (EMG), because muscle tone also differs between wakefulness and sleep. Eye movements during sleep are measured using electro-oculography (EOG). Other sensors can be added (pulseoxymeter, airflow etc.) These procedure is called polysomnographie (PSG) and allows to analyse the state of the patient during sleep. It also allows to track sleep related disease such as sleep apnea or restless-leg syndrom.
Dreem headband is a device able to measure sleep at home. It is easy to use and confortable compared to a classic PSG. Its aims to help people track and improve their sleep. The Dreem headband uses three kind of sensors: EEG electrods, accelerometer and pulseoximeter. Hence, it is able to measure brain activity, position, respiration, heartrate and movement all along the night. The device is also able to send sounds using bone conduction. Signals are analyzed online throughout the night and the device is able to perform sound stimulation to enhance deep sleep quality at different steps of the night : falling asleep, deep sleep and awakening. More info at dreem.com/product.
In this challenge, data consists on EEG signals acquired on the Dreem headband in sham condition i.e. without any kind of sound stimulations. Thus we aim to predict brain activity in normal condition.
Sleep progresses in cycles that involve multiple sleep stages : wake, light sleep, deep sleep, rem sleep. Different sleep stages are associated to different physiological functions. The represenation of the sleep stages through the night is called an hypnogram and is built from the physiological signals recorded by PSG and analyzed by window of 30seconds.
Deep sleep (also called slow wave sleep) occurs mainly in the first hours of sleep. It is associated with memory consolidation, energy restoration, hormone releasing. Electroencephalographic measurement in deep sleep is characterized by slow oscillations: trains of high magnitude and low frequency waves (1-4 Hz).
Deep Sleep can be enhanced by inducing slow oscillations through various kind of stimulations (auditory, visual, magnetic etc. see this publication). The Dreem headband is able to perform such sound stimulation during deep sleep.
In this dataset, we try to predict whether or not a slow oscillation will be followed by another one in sham condition, i.e. without any stimulation. This will allow to:
Each sample represents 10 seconds of recording starting 10 seconds before the end of a slow oscillation. Data provided consists of a N x 1261
matrix.
The prediction is a label in {0, 1, 2}.
High and low are defined with respect with the mean amplitude of slow oscillations measured on the whole record.
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
X_train = h5py.File("X_train.h5", "r")
y_train = pd.read_csv("y_train.csv").as_matrix()[:, 1].squeeze()
X_test = h5py.File("X_test.h5", "r")
def extract_features(h5):
data = h5["features"][:]
features = []
features.append(data[:, :11])
features.append(data[:, 11:].max(1).reshape(-1, 1))
features.append(data[:, 11:].min(1).reshape(-1, 1))
features.append(np.abs(data[:, 11:]).mean(1).reshape(-1, 1))
features = np.concatenate(features, 1)
return features
features_train = extract_features(X_train)
clf = RandomForestClassifier(n_estimators=10)
clf.fit(features_train, y_train)
features_test = extract_features(X_test)
y_pred = clf.predict(features_test)
with open("y_benchmark.csv", "w") as f:
f.write("".join(["id,label\n"] + ["{},{}\n".format(i, y) for i, y in enumerate(y_pred)]))
Files are accessible when logged in and registered to the challenge