Skip to main content

medpipe

GitHub License Python 3.12+ tests

Table of content

  1. Overview
  2. Installation
  3. Usage
    1. Preprocessing operations
    2. Models
    3. Recalibration
    4. Metrics
    5. Plots
  4. Examples

Overview

The medpipe package is a layer to help create AI models (classifiers and regressors) for clinical applications from tabular data. It covers data loading and preprocessing, model creation and training, recalibration, and visualisation.


Installation

To install medpipe use pip:

$ pip install medpipe

or clone the GitHub repository and install the package with pip:

$ git clone git@github.com:Surgical-Recovery-and-Safety-Lab/medpipe.git
$ cd medpipe
$ pip install .

NOTE: It is recommended to use a virtual environment (venv) to install this package.

Ensure that the installation was successful and that all tests pass by running the following command in the medpipe directory:

$ pytest 

Usage

This package was tested on a Linux distribution (Ubuntu 24.04) with Python v3.12.3. The sckit-learn was used as the base of most of the code.

A MedpipePipeline contains the preprocessing operations, a model for each prediction outcome, and a recalibration model (if specified) for each outcome. Thus, with only a few lines of code, several models can be created and fitted using the same data.

Preprocessing operations

Preprocessing operations are chained and applied sequentially. Available operations are listed in the sklearn.preprocessing and sklearn.impute modules.

Models

Any model from the sklearn.ensemble, sklearn.linear_model, and sklearn.isotonic modules are available. Additionally, models from the ngboost package can be used.

NOTE: The package can handle binary classifiers and regressors. However, handling of regressors is not as developed yet.

Recalibration

Two recalibration models are available: logistic regression (Platt scaling), and isotonic regression.

Metrics

The list of available metrics is the following:

Metric Description
Accuracy Proportion of all classifications that were correct.
Recall Proportion of all actual positives that were classified correctly (true positive rate).
Precision Proportion of all the positive classifications that are actually positive.
F1 score Harmonic mean of precision and recall.
AUROC Area under the ROC curve.
AP Area under the precision-recall curve.
Log loss Logarithmic loss.
Brier score Brier score loss.
ICI Integrated calibration index.
RMSE Root mean squared error.
MAE Mean absolute error.

NOTE: Metrics can be added by editing the METRIC_MAPPING map in the metrics/core.py module.

Plots

There are four different plots that can be generated (mainly for classifiers):

  1. Probability distribution, histrogram of predicted probabilities;
  2. ROC curve, receiver operating characteristic curve;
  3. Reliability diagram, classifier calibration curve;
  4. Fairness heatmap, heatmap of differences for different strata to assess model bias.

Examples

Minimal example based on configuration files:

import medpipe as mp

config_path = "config-examples/HGBc_config.toml"
pipe = mp.MedpipePipeline(config_path, logger=None)
pipe.run()  # Run pipeline based on configuration
pipe.save()  # Save pipeline

Example allowing the user more control over the data and plots:

import medpipe as mp

config_path = "config-examples/HGBc_config.toml"
pipe = mp.MedpipePipeline(config_path, logger=None)
data = load_data(pipe.medpipe_config.data.path)  # Load the data

# Get the different data sets
X_train, y_train, X_test, y_test, X_recal, y_recal, _ = pipe.get_data_sets(data)
pipe.fit(X_train, y_train, X_recal, y_recal)  # Fit the pipeline

# Make predictions for each outcome and plot some figures
for outcome in pipe.outcomes:
	y_preds = pipe.predict_proba(X_test, outcome)[0]
	mp.plot_ROC_curve(y_test, y_preds, "ROC curve")
	mp.plot_reliability_diagram(y_test, y_preds, "Calibration", strategy="quantile")
	

Metadata

Release files for medpipe 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medpipe 0.3.0
File Size Uploaded
medpipe-0.3.0.tar.gz 37.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for medpipe 0.3.0
File Interpreter ABI Platform
medpipe-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 78.0 kB

Release files / medpipe-0.3.0.tar.gz

Download URL medpipe-0.3.0.tar.gz
Size 37.3 kB
Tags Source
SHA-256 checksum
How to use checksums
91853b0a323ce77c96fa3a98c88abc6afa98fb28fb0ad76984a032b829a6c386
BLAKE2b-256 checksum
How to use checksums
d733e27f794cd272c55488257d896cd8bf4cb8964b91ccd2067ae06dcb974a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / medpipe-0.3.0-py3-none-any.whl

Download URL medpipe-0.3.0-py3-none-any.whl
Size 40.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acb6b20d97e8be45d3d5a847b9660e80dfc907c3b50d24e118fbc669c0816b58
BLAKE2b-256 checksum
How to use checksums
97771777aa8b0359d1b2615a61d7cc84311d70e11db6f501f204ae5dbc0aaa72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page