This release is a pre-release and may not be stable for production use.
medpipe
Table of content
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):
- Probability distribution, histrogram of predicted probabilities;
- ROC curve, receiver operating characteristic curve;
- Reliability diagram, classifier calibration curve;
- 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.4.0.dev2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| medpipe-0.4.0.dev2.tar.gz | 84.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| medpipe-0.4.0.dev2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 176.5 kB
Release files / medpipe-0.4.0.dev2.tar.gz
| Download URL | medpipe-0.4.0.dev2.tar.gz |
|---|---|
| Size | 84.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d0bee7ebee39e3d46c4a7c2df76e6cc23077016e245298dbb1cde78759f7fa5
|
|
BLAKE2b-256 checksum How to use checksums |
5e7088a5a86a7c57a0dedf08d55a611920bd9048180de51382fe61f53e2ce4ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / medpipe-0.4.0.dev2-py3-none-any.whl
| Download URL | medpipe-0.4.0.dev2-py3-none-any.whl |
|---|---|
| Size | 92.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51d9eb7c488c07beac590e1daef0b703f30ca35f348bb3f1a4f715a68fc05093
|
|
BLAKE2b-256 checksum How to use checksums |
7ed7da8c873aa3741bac76e88afb933219208875dd8e3ae22604305b8029b5c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|