OPEN SOURCE

Predicting Hospital Readmissions with Machine Learning: A Diabetic-Patient Risk Model

OCT 13, 2026·8 MIN READ

Predicting Hospital Readmissions with Machine Learning: A Diabetic-Patient Risk Model

TL;DR: An open-source machine learning pipeline that predicts 30-day hospital readmission risk for diabetic patients: synthetic clinical data generation (10,000 patient records), a sklearn preprocessing + Random Forest pipeline with class balancing, saved evaluation metrics, feature-importance analysis, and a persisted model. The reported metrics are modest and honest (ROC-AUC 0.65) — this article explains why that's the interesting part.

1. The problem: readmissions cost lives and money

Hospital readmission within 30 days of discharge is one of healthcare's most-watched quality metrics. High readmission rates signal gaps in care — discharge planning that didn't stick, medications patients couldn't manage, follow-ups that never happened — and they carry real financial penalties for hospitals. For diabetic patients specifically, readmission risk is driven by a tangle of factors: glycemic control (HbA1c), medication complexity, comorbidities, length of stay, and how the patient entered the system in the first place.

The intervention logic is simple and powerful: if you can identify high-risk patients at or before discharge, you can target them — intensified discharge planning, home-health follow-up, pharmacist medication review — instead of spreading the same thin resources across everyone. A risk model doesn't replace clinical judgment; it triages attention toward the patients most likely to be back within a month.

2. What the project is

healthcare-readmission-analytics is a Python ML pipeline that generates a synthetic diabetic-patient dataset, preprocesses it through a proper sklearn pipeline, trains a Random Forest classifier to predict the binary readmitted target, and persists both the metrics and the trained model. The repo includes a tests/ directory — a good sign of engineering discipline in a portfolio project — and is containerized with Docker.

Project structure (verified from the repo tree):

FileRole
data_generator.pyGenerates 10,000 synthetic patient records
model_pipeline.pyPreprocessing, training, evaluation pipeline
healthcare_dataset.csvGenerated dataset
readmission_model.joblibPersisted trained model
model_metrics.txtSaved classification report + ROC-AUC
confusion_matrix.png, feature_importance.pngGenerated visualizations
tests/Test suite

3. The data: synthetic, but clinically shaped

data_generator.py builds 10,000 patient records with a fixed seed (42) for reproducibility, using Faker for identifiers and numpy for the clinical distributions. The feature set mirrors the structure of real diabetes readmission datasets (in the spirit of the well-known UCI diabetes dataset): demographics (gender, age 18–90, race), admission details (admission type — Emergency/Urgent/Elective; discharge disposition; admission source; time in hospital), clinical counts (lab procedures, procedures, medications, diagnoses), diagnosis categories across three diagnosis slots (Circulatory, Respiratory, Digestive, Diabetes, Injury, and others), and the diabetes-specific labs that clinicians actually watch: glucose serum test results and A1C (HbA1c) results.

This is synthetic data — the relationships are simulated, not learned from real patients. But the schema is clinically sensible: the features a real readmission model would use, in roughly the distributions real hospital data shows. That's what makes the pipeline a legitimate rehearsal for real data rather than a toy.

4. The pipeline: preprocessing done right

model_pipeline.py gets the unglamorous parts right, which is where most portfolio projects fail:

The classifier is a RandomForestClassifier (100 trees, random_state=42) with class_weight='balanced' — the right call for readmission data, where readmitted patients are the minority class and a naive model would just predict "not readmitted" for everyone. Train/test uses a stratified 80/20 split. The script also imports GridSearchCV, signaling hyperparameter tuning as the natural next step.

5. The results — and why the modest numbers are the point

Here's model_metrics.txt, quoted verbatim:

ROC-AUC Score: 0.6502

Classification Report:
              precision    recall  f1-score   support
           0       0.73      0.97      0.83      2156
           1       0.52      0.08      0.14       844
    accuracy                           0.72      3000

An ROC-AUC of 0.65 and a recall of 0.08 on the readmitted class is not a triumph — it's an honest baseline. Most readmission models built on coarse administrative features land in exactly this zone; readmission is genuinely hard to predict from demographics and counts alone, and the class imbalance (844 positives out of 3,000) punishes recall. The reason this project is worth showcasing is precisely that it reports these numbers instead of hiding them. The confusion matrix is saved as a PNG, the classification report is saved as text, and the feature-importance plot identifies the top risk drivers (inpatient visit counts, age, HbA1c) — which, encouragingly, align with what clinicians would expect.

A portfolio project that reports ROC-AUC 0.65 on synthetic data is more trustworthy than one that reports 0.97. In healthcare ML, a suspiciously perfect number usually means the target leaked into the features.

6. From risk score to intervention: how this would actually be used

A risk model only matters if it changes who gets attention. The deployment sketch is simple: score the daily discharge list in batch, sort by predicted readmission probability, and hand the top decile to the care-transition team — pharmacist medication review, 48-hour follow-up call, home-health referral. The feature_importance.png output matters here as much as the score itself: the top drivers (inpatient visit counts, age, HbA1c levels) align with what clinicians already know, which is exactly what you want — a model whose reasoning a doctor recognizes is a model a doctor will trust enough to act on, even before per-patient SHAP explanations are added.

One operational subtlety the pipeline handles well: because preprocessing lives inside the sklearn Pipeline, the same artifact that was evaluated is the artifact that scores new patients. In healthcare deployments, train/serve skew — where the production data path transforms features slightly differently than training did — is a quiet killer of model performance. Encapsulating the transformations in the persisted .joblib eliminates an entire class of silent failures.

7. How to run it

git clone https://github.com/Shivay00001/healthcare-readmission-analytics.git
cd healthcare-readmission-analytics
pip install -r requirements.txt   # pandas, numpy, faker, scikit-learn, matplotlib, seaborn, joblib
python data_generator.py          # builds healthcare_dataset.csv (10,000 records)
python model_pipeline.py          # trains, evaluates, saves model + metrics + plots

The trained model is persisted as readmission_model.joblib — load it with joblib.load and pass a patient feature row through the pipeline for a risk score. Docker support is included for containerized runs. No external services, no cost, everything local.

8. Honest status and roadmap

What this is: a complete, tested, containerized ML pipeline demonstrating real healthcare-analytics methodology — synthetic data generation with clinical structure, leak-aware preprocessing, class-balanced training, and honest evaluation artifacts.

What it isn't: a clinical tool. It trains on synthetic data, reports modest baseline metrics, and has never touched real patient records — nor should anyone deploy it as if it had. Same caveat as its sibling repos: the README lists a broad BI stack (R, PowerBI, Tableau, Qlik Sense, BigQuery, SAS) that the Python code doesn't exercise; the actual stack is scikit-learn, pandas, and matplotlib.

The roadmap writes itself, and the code already points at it: use the imported GridSearchCV for real hyperparameter tuning; address the 0.08 recall with threshold tuning, SMOTE, or cost-sensitive learning (in readmission, a false negative costs more than a false positive); add SHAP-based per-patient explanations so a risk score comes with reasons a clinician can act on; and — the real milestone — retrain on de-identified real data, where the preprocessing discipline this pipeline demonstrates would finally meet features worth predicting on.

Frequently asked questions

What does the healthcare-readmission-analytics repo predict?

The likelihood that a diabetic patient is readmitted within 30 days of discharge, using demographics, admission details, diagnosis categories, and lab results (glucose, HbA1c) — trained on 10,000 synthetic patient records.

Why is the ROC-AUC only 0.65?

Readmission is genuinely hard to predict from coarse administrative features, and the data is synthetic. The honest baseline is the point — it sets the floor that better features, tuning, and real data would improve on.

Can this be used in a real hospital?

No — not as-is. It's a methodology demonstration on synthetic data. Real clinical deployment would require de-identified real data, clinical validation, and regulatory review.

How is the model served?

The trained pipeline is saved as readmission_model.joblib; preprocessing is encapsulated in the sklearn Pipeline, so inference applies identical transformations — no train/serve skew.

The bottom line

Readmission prediction is a hard, high-stakes problem where honest baselines beat inflated demos. This repo shows the full pipeline done correctly — clinically shaped synthetic data, leak-aware preprocessing, balanced training, and metrics reported without makeup — which is exactly the foundation a real clinical model would need.

Repo: github.com/Shivay00001/healthcare-readmission-analytics — MIT licensed. Building data-driven tools for healthcare operations? VisionQuantech designs analytics pipelines for clinics and health businesses. Contact: [email protected]

References & further reading

  1. github.com/Shivay00001/healthcare-readmission-analytics

Cite this article: Shivam Kumar (2026). Predicting Hospital Readmissions with Machine Learning: A Diabetic-Patient Risk Model. VisionQuantech. https://visionquantech.com/blog/showcase-healthcare-readmission-analytics.html

Want this for your business?

VisionQuantech builds AI receptionists, chatbots & automation for clinics, home services, real estate & more.

Book a Free Demo
SHARE𝕏in⧉
Chat with us Email us