Machine learning#

Prediction models for patient outcomes, from linear and gradient boosting models to recurrent and transformer networks for time series. Models are trained, calibrated and evaluated on patient-level splits of static and longitudinal data.

Tasks and splits#

ml.Task

A prediction target and the timepoints its features are computed from.

ml.split

Split observations into a training, a tuning and a held-out set.

Training and prediction#

ml.fit

Fit a model that predicts the targets of a task from variables and obs columns.

ml.predict

Predict the targets of every observation with a fitted model.

ml.Predictor

A model fitted by fit() with everything needed to compute its features.

Deep learning models#

These models need the ml extra, pip install 'ehrapy[ml]'.

ml.MLP

Multilayer perceptron on the summaries of longitudinal variables and the static covariates.

ml.GRU

Gated recurrent unit network on the time series of the variables, whether they were observed and the time since their last observation.

ml.LSTM

Long short-term memory network on the time series of the variables, whether they were observed and the time since their last observation.

ml.GRUD

GRU-D [CPC+18], a gated recurrent unit network whose inputs decay towards the mean and whose hidden state decays with the time since the last observation.

ml.TCN

Temporal convolutional network [BKK18] of causal convolutions on the time series of the variables, whether they were observed and the time since their last observation.

ml.Transformer

Transformer encoder [VSP+17] over timepoints, pooled with attention that is stored by predict().

ml.RETAIN

RETAIN [CBS+16], which weighs timepoints with attention that is stored by predict().

ml.DeepModel

A network whose embedding, together with the static covariates, feeds a linear output layer.

ml.Trainer

How deep learning models are trained.

Evaluation#

ml.evaluate

Evaluate predictions with bootstrap confidence intervals, overall or per subgroup.

Calibration and uncertainty#

ml.calibrate

Calibrate the predicted probabilities of a fitted model on held-out observations.

ml.conformalize

Add split conformal prediction sets for classification and intervals for regression to a fitted model.

Interpretation#

ml.permutation_importance

Compute how much the predictions of a fitted model rely on every variable.