A portfolio-grade proof of concept for clinic demand forecasting, uncertainty quantification and staffing decision support across a healthcare network.
The project goes beyond a forecasting leaderboard. It treats the operational question as a chain:
validated clinic data
→ fixed-origin forecasts
→ calibrated uncertainty
→ demand-target selection
→ staffing decisions
→ cost / unmet-demand evaluation
→ monitoring and serving
All included data are synthetic and contain no patient-level information.
Reviewing this project? Start with the project documentation or the committed decision evidence:
reports/evidence/capacity_target_benchmark/,reports/evidence/staffing_decision_benchmark/, andreports/evidence/hybrid_policy_benchmark/. Then usedocs/demo_guide.mdfor a 10-minute walkthrough.
- Data engineering: typed contracts and a configurable synthetic generator with overdispersion, demand episodes, changepoints, marketing effects and capacity censoring.
- Correct time-series evaluation: rolling-origin, fixed-origin multi-day evaluation. Lag-based global ML forecasts the complete holdout recursively; realised targets inside the holdout are never fed back as lag features.
- Model breadth with a common contract: baselines, SARIMAX, Prophet, global ML, Nixtla models, LSTM, foundation models and TimeGPT, with optional families isolated behind guarded imports.
- Uncertainty quantification: split-conformal intervals calibrated from the same recursive rolling-fold residuals used by deployment-style forecasts.
- Decision science: explicit separation between throughput forecasting and staffing demand targets, followed by costed policy comparison.
- Capacity-aware hybrid staffing: a prospectively frozen rule selects the clinical staffing target using only forecast-time information.
- Role-specific demand: clinicians/nurses use the selected hybrid clinical target; front desk uses scheduled appointments.
- Hierarchical coherence: clinic / region / network reconciliation.
- Operational engineering: batch pipelines, model registry, descriptive hybrid monitoring, FastAPI, CI, Docker and notebook execution checks.
- Responsible ML: model card, operational-risk documentation and explicit synthetic-data limits.
Healthcare networks need to decide how many clinicians, nurses and front-desk staff should be available at each clinic. Understaffing creates waiting-time pressure, overtime and unmet demand; overstaffing wastes budget and leaves capacity idle.
A subtle problem appears when the observed target is completed visits. Completed visits are capped by clinic capacity in the synthetic generator, so on busy days they can understate the demand that staffing actually needs to serve.
The repository therefore separates three quantities:
completed visits → observed throughput / legacy forecast target
attended demand → pre-capacity clinical demand
scheduled appointments → front-desk workload
Attended demand is reconstructed as:
scheduled appointments
- no-shows
- same-day cancellations
and capacity censoring is identified when attended demand exceeds completed visits.
The target decision was not made from intuition. It was built in three stages.
Completed-visits and attended-demand models were evaluated on identical fixed-origin folds and scored against realised attended demand.
On realised capacity-censored days, attended-demand forecasting improved WAPE, MAE, mean shortfall, bias and underforecast rate. On uncensored days, completed-visits forecasting remained modestly better. The evidence therefore did not support replacing completed visits everywhere.
The next benchmark held the front-desk forecast, staffing rules, roster caps and cost coefficients fixed and changed only the clinical target.
On censored days, attended-demand staffing reduced both total cost and unmet demand relative to completed-visits staffing. On uncensored days, the direction reversed. Again, no pure target dominated globally.
Before evaluating the hybrid, the switching rule was frozen:
if completed-visits 90% upper conformal bound >= known clinic capacity:
use attended-demand forecast for clinicians/nurses
else:
use completed-visits forecast for clinicians/nurses
front desk always uses scheduled appointments
The realised capacity_censored outcome is never an input to the switch.
It is evaluation-only.
Across four outer 28-day folds, the frozen hybrid averaged:
- about 9.31% fewer unmet visits than completed-visits-only staffing for about 0.70% higher total cost;
- about 0.32% lower total cost and 4.59% fewer unmet visits than attended-demand-only staffing.
On realised capacity-censored days, the hybrid beat both pure policies. The trigger is useful but not a perfect classifier: in the confirmatory run it fired on 83.64% of censored days and 24.26% of uncensored days.
These numbers are conditional on the synthetic generator, staffing productivity assumptions and cost coefficients. They are not real-clinic performance claims.
The operational planning horizon is a fixed-origin multi-day forecast. Therefore the primary evaluation asks each model to predict the entire holdout horizon from one origin.
For lag-based global ML:
train to origin
↓
drop future target / outcome columns
↓
recursive 28-day forecast
↓
score against held-out actuals
Teacher-forced predictions that use realised values from inside the test window are not used in the primary benchmark or conformal calibration. Historical one-fold teacher-forced global-ML WAPE values are retired.
The platform separates batch generation from read-only serving. The role-specific batch path computes forecasts, conformal uncertainty, the frozen hybrid target selection, staffing recommendations and monitoring, then snapshots an immutable serving run. The /v2 API reads those persisted artifacts and verifies manifest-selected file identity before serving; it never trains or recomputes the hybrid switch during a request.
See docs/architecture.md for the C4 Context and Container/runtime views plus the immutable /v2 serving sequence and provenance contract.
This project uses Poetry and targets Python 3.11.
poetry env use 3.11
poetry install
poetry run python scripts/generate_data.py
poetry run pytestRun the legacy completed-visits batch path:
poetry run python scripts/run_batch_forecast.py --horizon 28Run the operational role-specific hybrid path:
poetry run python scripts/run_role_specific_batch.py --horizon 28Start the API:
poetry run uvicorn clinic_forecast.api.main:app --reloadInteractive docs are available at:
http://127.0.0.1:8000/docs
The software/package version is currently 0.3.0 and is exposed through
clinic_forecast.__version__ and the FastAPI application metadata.
That project version is independent from the frozen role-specific serving schema
version. The /v2 contract currently remains 2.0.0; changing package code
does not automatically change the serving contract.
The API deliberately keeps two compatibility surfaces.
These endpoints continue to serve the original completed-visits batch outputs:
GET /health
GET /clinics
GET /forecasts
GET /staffing
POST /scenario/marketing
These endpoints serve the operational role-specific artefacts:
GET /v2/health
GET /v2/forecasts
GET /v2/staffing
GET /v2/hybrid-monitoring
GET /v2/contract
GET /v2/provenance
/v2/forecasts exposes both candidate clinical forecasts and intervals,
scheduled-demand forecasts, known clinic capacity, capacity_pressure,
hybrid_target, and the selected hybrid clinical forecast. This makes the
staffing decision auditable from the response itself.
The API trains nothing and recomputes no hybrid decision at request time. When a serving manifest exists, it serves manifest-selected immutable batch artefacts and verifies their path, size and SHA-256 identity before returning them. See docs/api_v2_contract.md and docs/architecture.md.
src/clinic_forecast/
├── backtesting.py fixed-origin recursive evaluation
├── capacity.py attended/unmet-demand reconstruction
├── capacity_benchmark.py paired target benchmark
├── decision_benchmark.py paired staffing-policy benchmark
├── hybrid_policy.py prospectively frozen switch
├── hybrid_benchmark.py three-policy confirmatory benchmark
├── hybrid_monitoring.py descriptive switch-use monitoring
├── contracts.py data contracts
├── data.py synthetic network generator
├── features.py leakage-safe feature engineering
├── intervals.py split-conformal intervals
├── metrics.py shared forecast metrics
├── reconciliation.py hierarchical reconciliation
├── staffing.py transparent staffing rules and cost scenarios
├── monitoring.py drift + quality monitoring
├── registry.py local model registry
├── role_specific.py attended/completed/scheduled target forecasts
├── serving_provenance.py immutable serving manifests and fingerprint checks
├── serving_snapshot.py immutable run snapshots and model bindings
├── models/ statistical, ML and optional model families
├── pipelines/
│ ├── batch_inference.py legacy completed-visits batch path
│ └── role_specific_batch.py operational hybrid batch path
└── api/main.py legacy + /v2 read-only serving
The core PoC runs without heavy optional dependencies.
poetry install --with optionalOptional tools include Prophet, XGBoost, LightGBM, the Nixtla ecosystem, PyTorch/LSTM, Chronos and TimeGPT. Optional models return the common forecast schema, but only models executed under the same fixed-origin multi-fold contract belong in the primary production-selection comparison.
| # | Notebook | Focus |
|---|---|---|
| 00 | Business problem and PoC design | Decisions, data entities, evaluation design |
| 01 | Synthetic data generation | Simulation design |
| 02 | EDA and forecastability | Demand structure |
| 03 | Statistical models | Baselines, SARIMAX, Prophet |
| 04 | Global ML forecaster | Features and recursive forecasting |
| 05 | Optional benchmarks | LSTM and TimeGPT |
| 06 | Staffing decision layer | Staffing rules, costs, no-shows |
| 07 | Hierarchical reconciliation | Clinic / region / network coherence |
| 08 | Marketing scenario planning | Predictive what-if analysis |
| 09 | Monitoring and retraining | Drift alerts and retraining policy |
| 10 | Executive summary | Historical end-to-end narrative |
| 11 | Fixed-origin model benchmark | Multi-fold 28-day benchmark |
Notebook 10 predates the final hybrid evidence chain. Where its single-target
staffing story differs from the committed evidence under reports/evidence/,
the committed benchmark results are authoritative.
Forecast evaluation reports WAPE, bias, MAE, RMSE, sMAPE and interval coverage. Decision evaluation adds:
- total cost;
- regular staffing cost;
- overtime cost;
- understaffing cost;
- idle cost;
- unmet visits;
- understaffed-day rate;
- clinician and nurse staff-days.
Committed evidence:
reports/evidence/capacity_target_benchmark/RESULTS.mdreports/evidence/staffing_decision_benchmark/interpretation.mdreports/evidence/hybrid_policy_benchmark/RESULT.md
The hybrid benchmark was evaluated only after its rule was frozen. Its full row-level paired decisions remain in the referenced GitHub Actions artefact; summary and provenance are committed in the repository.
CI runs:
- Ruff;
- mypy;
- pytest;
- notebook smoke execution;
- capacity-target benchmark evidence regression;
- staffing-decision benchmark evidence regression;
- hybrid-policy benchmark evidence regression.
This repository is deliberately production-shaped but is not a clinically validated production deployment. The explicit readiness review classifies each requirement as:
- implemented in this portfolio;
- requires deployment integration; or
- requires governed clinical evidence.
See docs/production_readiness.md before
interpreting CI, immutable serving, retraining rehearsal or monitoring as
evidence of deployment readiness.
After generating a role-specific serving run, verify the locally provable portfolio boundary with:
make readiness-checkThis checks immutable artefact fingerprints, v2 schemas, provenance and exact model/run bindings. A green result is deliberately not production or clinical certification.
The Markdown documentation under docs/ is published as a MkDocs Material site.
Build it locally with:
make docs-buildFor a local live preview:
make docs-serveDocumentation publication does not change the project's production-readiness or clinical-evidence boundaries.
reports/model_card.md— intended/out-of-scope use, target semantics, confirmatory evidence, limitations and human review.docs/operational_risk.md— forecast, data, decision-process and governance risks.docs/evaluation_strategy.md— fixed-origin evaluation and conformal-calibration contract.docs/hybrid_policy.md— frozen prospective switch.docs/api_v2_contract.md— versioned serving semantics.
The included data are synthetic. They mimic common healthcare-network demand patterns without exposing patient-level data or protected health information. Absolute accuracy and cost figures demonstrate methodology; they are not claims about a real healthcare network.
Release preparation is manual and auditable. Before tagging a version, run:
make release-checkThe check validates Poetry/package/FastAPI/CITATION/changelog version identity
but never creates a tag or publishes anything. See
CHANGELOG.md and docs/releasing.md.
Released under the MIT License. See the model card and operational risk register before adapting the project to real operations.