Skip to main content

ResPredAI

Antimicrobial resistance predictions via artificial intelligence models

PyPI Python Version CI License: MIT DOI

Implementation of the pipeline described in:

Bonazzetti, C., Rocchi, E., Toschi, A. et al. Artificial Intelligence model to predict resistances in Gram-negative bloodstream infections. npj Digit. Med. 8, 319 (2025). https://doi.org/10.1038/s41746-025-01696-x

ResPredAI Logo

Website | Documentation | Installation | Quick Start | Pipeline Overview | CLI Commands | Citation

A reproducible machine learning framework designed to accelerate clinical decision-making by predicting antimicrobial resistance patterns from patient data.

Highlights

  • Leakage-safe nested cross-validation: one-hot encoding, imputation and scaling are fitted inside each training fold, a group_column keeps every patient on one side of each split, and repeated or temporal (prospective-style) validation is one setting away
  • Nine models, one configuration file: logistic regression, random forest, XGBoost, CatBoost, MLP, two SVMs, KNN and TabPFN (optional extra), each tuned in an inner CV
  • Metrics that matter for resistance prediction: very major and major errors (VME, ME) next to AUROC, MCC, balanced accuracy, Brier score and ECE, with the decision threshold tuned for Youden, F1, F2 or VME/ME costs
  • Honest uncertainty: bootstrap confidence intervals on the pooled out-of-fold predictions, resampling whole patients when a group_column is set, and split-conformal prediction sets with per-class coverage
  • Calibrated probabilities: Platt or isotonic calibration, with reliability curves per fold
  • Interpretability and subgroups: signed coefficients, native importances or SHAP, and performance tables per subgroup (e.g. ward, sex)
  • From study to deployment: train fits the final models on the whole cohort and evaluate scores them on an external one
  • Reproducible by default: one HTML report per run and a manifest with package versions, seed, git commit and data hash

Excerpt of the ResPredAI HTML report
Excerpt of the HTML report written by respredai run on the bundled example data.

Installation

pip install respredai
respredai --version  # check the installation

Or install from source:

git clone https://github.com/EttoreRocchi/ResPredAI.git
cd ResPredAI
# For development (includes pytest)
pip install -e ".[dev]"

Optional: TabPFN support

TabPFN is shipped as an optional extra to keep the base install lean:

pip install "respredai[tabpfn]"

TabPFN v3 also requires a PriorLabs API token. Export it before running any pipeline that includes TabPFN in [Pipeline] models:

export TABPFN_TOKEN="your-token-here"

If TabPFN is requested without the extra installed or without the token set, ResPredAI fails at the start of the run.

Quick Start

1. Create a configuration file

respredai create-config my_config.ini

The template is commented and comes with sensible defaults. A minimal valid configuration looks like this:

[Data]
data_path = ./data/my_data.csv
targets = Target1,Target2
continuous_features = Feature1,Feature2,Feature3

[Pipeline]
models = LR,RF,XGB,CatBoost
outer_folds = 5
inner_folds = 3

[Reproducibility]
seed = 42

[Log]
verbosity = 1
log_basename = respredai.log

[Resources]
n_jobs = -1

[Output]
out_folder = ./output/

The optional sections ([Metadata] for patient grouping, temporal and subgroup columns, [Uncertainty], [Validation], [Imputation], [ModelSaving], ...) are described in the configuration reference.

2. Check the configuration and run the pipeline

respredai validate-config my_config.ini --check-data
respredai run --config my_config.ini

3. Open the report

All results end up in out_folder; start from report.html.

Pipeline Overview

ResPredAI pipeline: split the data, fit on each training set, aggregate across folds and write the report; train and evaluate for deployment

Every model and target goes through the same steps; the amber ones are switched on in the configuration.

CLI Commands

Command What it does
run Nested CV and/or temporal validation for every model and target, with metrics, plots and the HTML report
train Fits the final models on the whole dataset and saves them with their threshold and conformal calibration
evaluate Scores saved models on a new labelled dataset, with bootstrap CIs and conformal prediction sets
feature-importance Coefficients, native importances or SHAP across the outer folds (needs [ModelSaving] enable = true)
create-config Writes a commented template configuration
validate-config Checks a configuration, and optionally the dataset, without running anything
list-models Lists the available models and their codes
info Shows the version and how to cite ResPredAI
respredai run --config my_config.ini [--models LR,RF] [--targets Target1] [--output ./out/] [--seed 0] [--validation-strategy both] [--quiet]
respredai train --config my_config.ini [--models LR,RF] [--output ./trained/]
respredai evaluate --models-dir ./output/trained_models --data new_data.csv --output ./eval/
respredai feature-importance --output ./output/ --model LR --target Target1 [--top-n 20] [--direction]

Command-line options override the configuration file. Each command page lists all its options.

Output

respredai run writes everything to out_folder:

  • report.html: self-contained report with metrics and their confidence intervals, confusion matrices, calibration diagnostics and subgroup tables
  • metrics/: one CSV per model and target with the fold mean, std and Nadeau-Bengio SE, the pooled out-of-fold estimate with its bootstrap CI (the uncertainty of this cohort's estimate with the fold models held fixed) and the conformal diagnostics, plus summaries across models
  • confusion_matrices/, calibration/: heatmaps and reliability curves
  • subgroup_analysis/: descriptive per-subgroup metrics, with CIs and a flag for small subgroups (if subgroup_columns is set)
  • models/: fold models used to resume interrupted runs and to extract feature importance (if model saving is enabled)
  • reproducibility.json: package versions, seed, n_jobs, git commit and data hash

The full layout, including the temporal-validation files, is in the output reference.

Notes

Changelog

See the full history of changes in the CHANGELOG.md file.

Citation

If you use ResPredAI in your research, please cite:

@article{Bonazzetti2025,
  author = {Bonazzetti, Cecilia and Rocchi, Ettore and Toschi, Alice and Derus, Nicolas Riccardo and Sala, Claudia and Pascale, Renato and Rinaldi, Matteo and Campoli, Caterina and Pasquini, Zeno Adrien Igor and Tazza, Beatrice and Amicucci, Armando and Gatti, Milo and Ambretti, Simone and Viale, Pierluigi and Castellani, Gastone and Giannella, Maddalena},
  title = {Artificial Intelligence model to predict resistances in Gram-negative bloodstream infections},
  journal = {npj Digital Medicine},
  volume = {8},
  pages = {319},
  year = {2025},
  doi = {10.1038/s41746-025-01696-x},
  url = {https://doi.org/10.1038/s41746-025-01696-x}
}

Funding

This research was supported by EU funding within the NextGenerationEU-MUR PNRR Extended Partnership initiative on Emerging Infectious Diseases (Project no. PE00000007, INF-ACT).

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines on setting up a development environment, running tests, and submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for ResPredAI 1.10.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 ResPredAI 1.10.0
File Size Uploaded Provenance Actions
respredai-1.10.0.tar.gz 90.5 kB Without provenance Details for respredai-1.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ResPredAI 1.10.0
File Interpreter ABI Platform Actions
respredai-1.10.0-py3-none-any.whl Python 3 none any Details for respredai-1.10.0-py3-none-any.whl

Total release size: 189.1 kB

Release files / respredai-1.10.0.tar.gz

Download URL respredai-1.10.0.tar.gz
Size 90.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e1ee15fe8e35221cbce25090f305cf768e4c9a65c2f0edc6d9e9eb0b708a4aba
BLAKE2b-256 checksum
How to use checksums
cd318c4d7d59649792353def8725a79e0b1af30c0fd42101aad45d1f0e4418f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / respredai-1.10.0-py3-none-any.whl

Download URL respredai-1.10.0-py3-none-any.whl
Size 98.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16645a48614cc9dfb093e6509ddb2f84c6e63293434dfec4c64bdba7257ecb93
BLAKE2b-256 checksum
How to use checksums
2bd189573cef958a11e503345b9c4c575d740996025f1cd7d6208d8941f6a5de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for ResPredAI 1.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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