Hospital Capacity Forecasting

Production MLOps pipeline for ICU bed demand forecasting with drift detection and monitoring dashboard.

The Problem

Hospitals operate on thin margins. Overstaffing burns cash — understaffing kills. ICU nurse staffing is typically done via manual judgment (“yesterday’s census plus some buffer”). This breaks during demand surges (flu season, COVID waves) and costs ~$50K/month per hospital in wasted labor.

The challenge wasn’t just prediction — it was trust. Hospital administrators need to:

  • Know when the model is stale (data drift detection)
  • Understand why a spike is predicted (feature interpretability)
  • Roll back to yesterday’s model if something looks wrong (< 5 min)
  • See everything on a dashboard, not Jupyter notebooks

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    DATA INGESTION                            │
│  HHS healthdata.gov API ──▶ CSV Parquet ──▶ Pull Manifest   │
└──────────────────────────┬──────────────────────────────────┘
                           │
┌──────────────────────────▼──────────────────────────────────┐
│                   FEATURE ENGINEERING                        │
│  Lags (1,7,14) ──▶ Rolling Stats (7,14,30) ──▶ Calendar    │
│  Missingness Indicators ──▶ Per-State Median Imputation     │
└──────────────────────────┬──────────────────────────────────┘
                           │
┌──────────────────────────▼──────────────────────────────────┐
│              MODEL TRAINING (ZenML Pipeline)                 │
│                                                              │
│  ┌──────────┐    ┌──────────┐    ┌──────────────┐          │
│  │  Ridge    │    │ XGBoost  │    │  Naive       │          │
│  │ (Floor)   │    │(Production│   │ (Baseline)   │          │
│  └──────────┘    └──────────┘    └──────────────┘          │
│                                                              │
│  ◆ Asymmetric RMSE (underprediction ×3) — primary metric    │
│  ◆ Direct multi-output (t+1 to t+7 in one shot)             │
│  ◆ MLflow tracking + model registry                         │
└──────────────────────────┬──────────────────────────────────┘
                           │
┌──────────────────────────▼──────────────────────────────────┐
│              SERVING + MONITORING                            │
│                                                              │
│  FastAPI (:8002) ──▶ /predict ──▶ /health                   │
│  Drift Pipeline ──▶ PSI + KS Test ──▶ JSON Reports          │
│  Streamlit Dashboard ──▶ Live Drift Plots + Health Metrics  │
│  CI/CD ──▶ GitHub Actions (test + lint + Docker build)      │
└─────────────────────────────────────────────────────────────┘

Design Decisions

Asymmetric Loss Function

Standard RMSE treats over- and under-prediction equally. For ICU staffing, underprediction by 10 beds means turning away critical patients. Overprediction by 10 means paying for idle staff. We use asymmetric RMSE with ×3 penalty on underprediction — the model learns to err on the side of safety.

Direct Multi-Output Forecasting

Instead of recursive forecasting (predict t+1, feed back as input for t+2…), we train one model per horizon. This avoids recursive error compounding — critical for 7-day horizons where small errors compound rapidly.

Temporal Splits Only

Random train/test splits leak future information into training. We use strict temporal ordering — train on past, validate on recent past, test on the last 30 days. This reflects real deployment conditions.

Drift Detection (PSI + KS)

Two statistical tests catch different failure modes:

  • PSI (Population Stability Index): Detects gradual distribution shifts in individual features
  • KS Test (Kolmogorov-Smirnov): Detects abrupt distribution changes

Combined, they catch both slow degradation and sudden data pipeline failures.

Results

Model Asymmetric RMSE (↓) MAE (↓) Underprediction Rate (↓)
Naive (yesterday’s value) 1.000 (baseline) 0.850 48%
Ridge Regression 0.720 0.580 35%
XGBoost (production) 0.540 0.410 22%

Metrics on held-out test set (last 30 days), aggregated across 7-day horizon.

Key Files

File Purpose
src/pipelines/training_pipeline.py ZenML training pipeline orchestration
src/monitoring/drift_detector.py PSI + KS drift detection
src/monitoring/data_health.py Schema, missingness, freshness checks
src/dashboard/app.py Streamlit monitoring dashboard
tests/test_monitoring.py Unit tests for drift + health modules

What I Learned

  • Silent failures are the real risk. A model making confident wrong predictions is worse than one that refuses to predict. Drift detection prevents this.
  • Training-serving skew is the #1 production bug. Bundling preprocessing inside the sklearn pipeline (not as a separate step) ensures identical computation at train and serve time.
  • Asymmetric metrics change model behavior. The same XGBoost with asymmetric loss produces systematically different predictions — safer for staffing.
  • Temporal splits are non-negotiable. Random splits gave AUC 0.95; temporal splits gave 0.78. The honest number is the one you deploy with.
  • GitHub: https://github.com/Harisathwik/hospital-capacity-forecasting
  • Live Dashboard: https://hospital-capacity-forecasting.streamlit.app/
  • Data Source: https://healthdata.gov/Hospital/COVID-19-Reported-Patient-Impact-and-Hospital-Cap/g62h-syeh