Nested cross-validation
Outer folds for evaluation, inner folds for tuning. Group-aware and repeatable, with preprocessing fitted on training folds only.
ResPredAI is an open-source Python pipeline that turns routinely collected clinical data into calibrated, interpretable resistance predictions. It implements the framework of our npj Digital Medicine study on Gram-negative bloodstream infections, ready to be re-run on your own cohort.
pip install respredai
Capabilities
ResPredAI builds the methodological safeguards into the pipeline itself: leakage-safe validation, calibrated probabilities and thresholds that reflect clinical costs. Results are designed to hold up outside the training cohort.
Outer folds for evaluation, inner folds for tuning. Group-aware and repeatable, with preprocessing fitted on training folds only.
Prospective-style evaluation with a date cutoff or ratio split, alone or alongside cross-validation.
Train on one cohort with train, then score another with evaluate using the saved preprocessing.
Platt or isotonic calibration, assessed with Brier score, ECE/MCE and reliability curves.
Youden, F1, F2 or cost-sensitive thresholds that weigh very major errors (VME) against major errors (ME).
Per-class (Mondrian) sets, {S}, {R} or {S,R}, that flag the cases the model cannot call at the chosen α.
Bootstrap confidence intervals and corrected standard errors (Nadeau–Bengio) alongside each point estimate.
Native or SHAP-based importance, with risk (+) or protective (−) direction for each feature.
The full metric set per clinical subgroup, with sample size and prevalence reported next to it.
Simple, KNN or iterative (MissForest-style) imputation, fitted within each training fold.
A self-contained HTML report plus a reproducibility manifest with environment, data fingerprint and configuration.
How it works
Every step that learns from data is refitted inside each outer fold, so the held-out patients never influence the model that is scored on them.
INI configuration, input validation, column checks
Outer CV fold × k folds × repeats group-aware
One-hot encoding, imputation and scaling fitted on the training fold
Grid search over hyperparameters
inner CVPost-hoc Platt or isotonic calibration
Youden, F-score or VME/ME cost-weighted
Held-out fold: probabilities, labels and conformal sets
Metrics with CIs, subgroups, calibration plots, HTML report
Temporal validation runs the same steps on a single time-based split. Read the run reference →
Quickstart
pip install respredai
TabPFN is an optional extra: pip install "respredai[tabpfn]", which also needs a PriorLabs API token.
respredai create-config my_config.ini
respredai validate-config my_config.ini --check-data
Point the template at your data, targets and features, then check it before running.
respredai run --config my_config.ini
Metrics, plots, trained fold models and report.html land in the output folder.
[Data]
data_path = ./data/my_data.csv
targets = Target1,Target2
continuous_features = Age,Creatinine,LOS
[Metadata]
# keep each patient in a single fold
group_column = PatientID
subgroup_columns = ward, sex
[Pipeline]
models = LR,RF,XGB,CatBoost
outer_folds = 5
inner_folds = 3
calibrate_probabilities = true
calibrate_threshold = true
# missing a resistance costs more
threshold_objective = cost_sensitive
vme_cost = 2.0
me_cost = 1.0
[Uncertainty]
alpha = 0.1
Command line
Each command reads the same INI configuration, so moving from internal to external validation needs no new code.
respredai run
Nested cross-validation and/or temporal validation, with metrics, plots and the HTML report.
respredai feature-importance
Importance or coefficients across outer folds, optionally with risk/protective direction.
respredai train
Train on the full dataset with inner-CV tuning and save one model per model–target pair.
respredai evaluate
Apply trained models to a new cohort and compute metrics against its ground truth.
Outputs
Every run writes CSV metrics, publication-ready figures and a single HTML report that collects them.
Generated by respredai run on the synthetic example dataset shipped with the package.
Research
Studies that develop or apply ResPredAI. New work from the project will be listed here as it is published.
Loading from OpenAlex…
Using ResPredAI in your research? Let us know on GitHub and we will feature it here.
Roadmap
Release themes in order. Planned releases may change in scope or sequence; the changelog records what has shipped.
Team
Institution
Institution
The original study was a collaboration of 16 authors. See the full author list or all code contributors.
Funding
This research was supported by the European Union – NextGenerationEU through the Italian Ministry of University and Research (MUR) under the National Recovery and Resilience Plan (NRRP).