Data sets and models
Classifier models
SleepWakeClassifier
SleepWakeClassifier (model=None, data_processor=None, scaler_pipeline_name:str='scaler', model_pipeline_name:str='model')
Abstract class for sleep/wake classifiers.
train_pipeline
train_pipeline (classifier:__main__.SleepWakeClassifier, examples_X:List[numpy.ndarray]=[], examples_y:List[numpy.ndarray]=[], pairs_Xy:List[Tuple[numpy.ndarray,numpy.ndarray]]=[], **train_kwargs)
*Assumes data is already preprocessed using get_needed_X_y and ready to be passed to the classifier.
Returns the loss history of the model.*
| Type | Default | Details | |
|---|---|---|---|
| classifier | SleepWakeClassifier | The classifier object. | |
| examples_X | List | [] | List of input examples. If non-empty, then examples_y must also be provided and must have the same length. |
| examples_y | List | [] | List of target labels. If non-empty, then examples_X must also be provided and must have the same length. |
| pairs_Xy | List | [] | List of input-target pairs. If non-empty, then examples_X and examples_y must not be provided. |
| train_kwargs | |||
| Returns | List | The loss history of the model. |
SleepWakeClassifier.train
SleepWakeClassifier.train (examples_X:List[numpy.ndarray]=[], examples_y:List[numpy.ndarray]=[], pairs_Xy:Li st[Tuple[numpy.ndarray,numpy.ndarray]]=[], **training_kwargs)
*Assumes data is already preprocessed using get_needed_X_y and ready to be passed to the model.
Returns the loss history of the model.*
SGD Linear Classifier
LinearModel
LinearModel (value, names=None, module=None, qualname=None, type=None, start=1)
Defines the loss used in sklearn’s SGDClassifier which defines the linear model used for classification.
SGDLinearClassifier
SGDLinearClassifier (data_processor:pisces.data_sets.DataProcessor|None= None, linear_model:__main__.LinearModel=<LinearModel .LOGISTIC_REGRESSION: 'log_loss'>, **kwargs)
Uses Sk-Learn’s SGDCLassifier to train a model. Possible models are logistic regression, perceptron, and SVM. The SGD aspect allows for online learning, or custom training regimes through the partial_fit method. The model is trained with a balanced class weight, and uses L1 regularization. The input data is scaled with a StandardScaler before being passed to the model.
Random Forest
RandomForest
RandomForest (data_processor:pisces.data_sets.DataProcessor|None=None, class_weight:str='balanced', **kwargs)
Interface for sklearn’s RandomForestClassifier
Mads Olsen et all classifier
We have downloaded the saved model weights from a research repository from Mads Olsen’s group, and converted those into a saved Keras model to remove the need to re-define all of the layers. This conversion process is shown in ../analyses/convert_mads_olsen_model_to_keras.ipynb.
Thus, we have a TensorFlow model that we can run inference on, and we could train it if we wanted to.
For simplicity, we are just going to run inference. One twist of our method is that the classifier is expecting two high-resolution spectrograms for inputs: 1. 3-axis Accelerometer data 2. PPG (photoplethysmogram) data
Based on visually inspecting examples from the paper, we are going to hack together an input by flipping the accelerometer data along the frequencies axis. The paper images seem to show a similarity between high-frequency accelerometer data and low-frequency PPG data. Surprisingly, this seems to work well.
MOResUNetPretrained
MOResUNetPretrained (data_processor:pisces.data_sets.DataProcessor|None= None, model:keras.src.models.model.Model|None=None, lazy_model_loading:bool=True, initial_lr:float=1e-05, validation_split:float=0.1, epochs:int=10, batch_size:int=1, **kwargs)
Abstract class for sleep/wake classifiers.
Training tools
run_splits
run_splits (split_maker:__main__.SplitMaker, data_processor:pisces.data_sets.DataProcessor, swc_class:Type[__main__.SleepWakeClassifier], epochs:int|None, exclude:List[str]=[], linear_model:__main__.LinearModel|None=None)
run_split
run_split (train_indices, preprocessed_data_set:List[Tuple[numpy.ndarray,numpy.ndarray]] , swc:__main__.SleepWakeClassifier, epochs:int)
LeaveOneOutSplitter
LeaveOneOutSplitter ()
Initialize self. See help(type(self)) for accurate signature.
SplitMaker
SplitMaker ()
Initialize self. See help(type(self)) for accurate signature.