Skip to main content

Antimicrobial Resistance predictions via AI models

Project description

ResPredAI

Antimicrobial resistance predictions via artificial intelligence models

PyPI Python Version CI License: MIT

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 | CLI Commands | Citation

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

Links

  • Project Website - Overview of the project, original paper, and related work
  • Documentation - Installation guides, CLI reference, tutorials, and API documentation

Installation

Install from PyPI:

pip install respredai

Or install from source:

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

Testing the Installation

Verify the installation:

respredai --version

Quick Start

1. Create a configuration file

respredai create-config my_config.ini

2. Edit the configuration file

Edit my_config.ini with your data paths and parameters:

[Data]
data_path = ./data/my_data.csv
targets = Target1,Target2
continuous_features = Feature1,Feature2,Feature3
# group_column = PatientID  # Optional: prevents data leakage when you have multiple samples per patient

[Pipeline]
models = LR,RF,XGB,CatBoost
outer_folds = 5
inner_folds = 3
calibrate_threshold = false
threshold_method = auto

[Reproducibility]
seed = 42

[Log]
verbosity = 1
log_basename = respredai.log

[Resources]
n_jobs = -1

[ModelSaving]
enable = true
compression = 3

[Imputation]
method = none
strategy = mean
n_neighbors = 5
estimator = bayesian_ridge

[Output]
out_folder = ./output/

3. Run the pipeline

respredai run --config my_config.ini

CLI Commands

Run the pipeline

respredai run --config path/to/config.ini [--quiet]

Train models using nested cross-validation with the specified configuration.

๐Ÿ“– Detailed Documentation - Complete guide with all configuration options and workflow details.

Train models for cross-dataset validation

respredai train --config path/to/config.ini [--models LR,RF] [--output ./trained/]

Train models on the entire dataset using GridSearchCV for hyperparameter tuning. Saves one model file per model-target combination for later use with evaluate.

๐Ÿ“– Detailed Documentation - Complete guide with output structure and workflow.

Evaluate on new data

respredai evaluate --models-dir ./output/trained_models --data new_data.csv --output ./eval/

Apply trained models to new data with ground truth. Outputs predictions and metrics.

๐Ÿ“– Detailed Documentation - Complete guide with data requirements and output format.

Extract feature importance

respredai feature-importance --output <output_folder> --model <model_name> --target <target_name> [--top-n 20]

Extract and visualize feature importance/coefficients from trained models across all outer cross-validation iterations. Uses SHAP as fallback for models without native feature importance.

๐Ÿ“– Detailed Documentation - Complete guide with interpretation, examples, and statistical considerations.

List available models

respredai list-models

Display all available machine learning models with descriptions.

Available Models:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Code       โ”‚ Name                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ LR         โ”‚ Logistic Regression      โ”‚
โ”‚ MLP        โ”‚ Neural Network           โ”‚
โ”‚ XGB        โ”‚ XGBoost                  โ”‚
โ”‚ RF         โ”‚ Random Forest            โ”‚
โ”‚ CatBoost   โ”‚ CatBoost                 โ”‚
โ”‚ TabPFN     โ”‚ TabPFN                   โ”‚
โ”‚ RBF_SVC    โ”‚ RBF SVM                  โ”‚
โ”‚ Linear_SVC โ”‚ Linear SVM               โ”‚
โ”‚ KNN        โ”‚ K-Nearest Neighbors      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Create a template configuration file

respredai create-config output_path.ini

Generate a template configuration file that you can edit for your data.

๐Ÿ“– Detailed Documentation - Complete guide to configuration file structure and customization.

Validate a configuration file

respredai validate-config <path_to_config.ini> [--check-data]

Validate a configuration file without running the pipeline. It can also check that the dataset load without errors.

๐Ÿ“– Detailed Documentation - Complete guide to configuration file validation.

Show information

respredai info

Display information about ResPredAI including scientific paper citation and version details.

Or just:

respredai --version

to show the installed version of ResPredAI.

Output

The pipeline generates:

  • Confusion matrices: PNG files with heatmaps showing model performance for each target
  • Detailed metrics tables: CSV files with comprehensive metrics (precision, recall, F1, MCC, balanced accuracy, AUROC) with mean, std, and 95% CI
  • Trained models: Saved models for resumption and feature importance extraction (if model saving enabled)
  • Feature importance: Plots and CSV files showing feature importance/coefficients (generated separately)
  • Log files: Detailed execution logs (if verbosity > 0)

Output Structure

output_folder/
โ”œโ”€โ”€ models/                                         # Trained models (if model saving enabled)
โ”‚   โ””โ”€โ”€ {Model}_{Target}_models.joblib
โ”œโ”€โ”€ trained_models/                                 # Models for cross-dataset validation (from train command)
โ”‚   โ”œโ”€โ”€ {Model}_{Target}.joblib
โ”‚   โ””โ”€โ”€ training_metadata.json
โ”œโ”€โ”€ metrics/                                        # Detailed performance metrics
โ”‚   โ”œโ”€โ”€ {target_name}/
โ”‚   โ”‚   โ”œโ”€โ”€ {model_name}_metrics_detailed.csv
โ”‚   โ”‚   โ””โ”€โ”€ summary.csv                            # Summary across all models
โ”‚   โ””โ”€โ”€ summary_all.csv                            # Global summary
โ”œโ”€โ”€ feature_importance/                             # Feature importance (if extracted)
โ”‚   โ””โ”€โ”€ {target_name}/
โ”‚       โ”œโ”€โ”€ {model_name}_feature_importance.csv    # Importance values
โ”‚       โ””โ”€โ”€ {model_name}_feature_importance.png    # Barplot visualization
โ”œโ”€โ”€ confusion_matrices/                             # Confusion matrix heatmaps
โ”‚   โ””โ”€โ”€ Confusion_matrix_{model_name}_{target_name}.png
โ”œโ”€โ”€ report.html                                     # Comprehensive HTML report
โ””โ”€โ”€ respredai.log                                   # Execution log (if verbosity > 0)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

respredai-1.4.1.tar.gz (50.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

respredai-1.4.1-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file respredai-1.4.1.tar.gz.

File metadata

  • Download URL: respredai-1.4.1.tar.gz
  • Upload date:
  • Size: 50.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for respredai-1.4.1.tar.gz
Algorithm Hash digest
SHA256 0401cfe2fb1f8d26055a10073afede810b8632b0f74fa6ebb82c7574a060ab8a
MD5 65cd2ac3408ecb61207519aadde77e0a
BLAKE2b-256 55e2d601e77a77f60d6fa1e7519f52207e12778da25ecd754987e2cac9119cd6

See more details on using hashes here.

File details

Details for the file respredai-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: respredai-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for respredai-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59a8dd8cc0c215c9e0abca8865077a12e47a0e8c88f5eaf430b0bbe4709c0081
MD5 4cba087511066723567210e1e943a998
BLAKE2b-256 1fcde2a726d2ccce18c62e66c7cad732c446e441b8b3340897fd8d2a44522a18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page