Skip to content

Latest commit

Β 

History

64 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🦠 Pandemic Intelligence System

Multi-Modal COVID-19 Forecasting, Risk Modeling & Policy Impact Analysis Platform

Python PyTorch FastAPI Streamlit XGBoost Docker License CI/CD


An end-to-end AI system for pandemic surveillance, forecasting, and decision support β€” designed for government agencies, healthcare organizations, and public health researchers.


πŸš€ Web Link Live : https://pandemic-intelligence.streamlit.app/

πŸ“‹ Table of Contents


πŸ”­ Overview

The Pandemic Intelligence System is a production-grade, research-quality AI platform that transforms raw COVID-19 epidemiological data into actionable intelligence. It combines classical time-series methods, deep learning, and explainable machine learning into a unified decision-support system.

This project was designed to demonstrate the full ML engineering lifecycle β€” from raw data ingestion to a live deployed API and interactive dashboard β€” using industry-standard tools and best practices.

What it solves:

  • Governments need early warning of outbreak surges before they become unmanageable
  • Healthcare systems need risk stratification across hundreds of countries simultaneously
  • Policymakers need "what-if" simulation before imposing restrictions
  • Researchers need reproducible, explainable models β€” not black boxes

✨ Key Features

Module Feature Technology
Data Engineering Merges 6 datasets, 70+ engineered features Pandas, NumPy
Forecasting 7/14/30-day predictions per country LSTM + Attention, Prophet, ARIMA
Risk Scoring Low/Medium/High classification with probability XGBoost + SHAP
Anomaly Detection Real-time outbreak surge detection Isolation Forest + LSTM Autoencoder
Explainability SHAP values for every risk prediction SHAP, matplotlib
REST API Production-ready endpoints with Pydantic validation FastAPI, uvicorn
Dashboard Interactive multi-page dark-theme UI Streamlit, Plotly
Deployment Containerized, CI/CD enabled Docker, GitHub Actions

πŸ— System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         DATA SOURCES (6 CSVs)                       β”‚
β”‚  full_grouped Β· covid_clean Β· worldometer Β· country_wise Β· day_wise β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        DATA PIPELINE                                β”‚
β”‚                                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
β”‚  β”‚  Data Cleaning  │───▢│  Feature Engineering β”‚                    β”‚
β”‚  β”‚  β€’ Merge CSVs   β”‚    β”‚  β€’ Rolling averages  β”‚                    β”‚
β”‚  β”‚  β€’ Null handlingβ”‚    β”‚  β€’ Growth rate, CFR  β”‚                    β”‚
β”‚  β”‚  β€’ Name mapping β”‚    β”‚  β€’ Lag features (14) β”‚                    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          MODEL LAYER                                β”‚
β”‚                                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  LSTM + Attentionβ”‚  β”‚   XGBoost Risk   β”‚  β”‚  Isolation Forestβ”‚  β”‚
β”‚  β”‚  ─────────────── β”‚  β”‚  ──────────────  β”‚  β”‚  + LSTM Autoenc. β”‚  β”‚
β”‚  β”‚  Time-series     β”‚  β”‚  Classification  β”‚  β”‚  ────────────── β”‚  β”‚
β”‚  β”‚  forecasting     β”‚  β”‚  Low/Med/High    β”‚  β”‚  Outbreak detect β”‚  β”‚
β”‚  β”‚  7/14/30 days    β”‚  β”‚  + SHAP explain  β”‚  β”‚  Surge warning   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                         β”‚
β”‚  β”‚   Prophet        β”‚  β”‚   ARIMA/SARIMA   β”‚                         β”‚
β”‚  β”‚  (seasonal)      β”‚  β”‚   (baseline)     β”‚                         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       API LAYER  (FastAPI)                          β”‚
β”‚                                                                      β”‚
β”‚     POST /predict    POST /risk    POST /anomaly    GET /summary    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    DASHBOARD  (Streamlit)                           β”‚
β”‚                                                                      β”‚
β”‚   Global Map Β· Forecasting Β· Risk Assessment Β· Anomaly Β· Analysis  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ›  Tech Stack

Machine Learning & Data Science

Library Version Purpose
torch 2.1.0 LSTM with Multi-Head Attention, LSTM Autoencoder
xgboost 2.0.0 Risk classification
prophet 1.1.5 Seasonal time-series forecasting
statsmodels 0.14.0 ARIMA/SARIMA baseline models
scikit-learn 1.3.2 Isolation Forest, preprocessing, cross-validation
shap 0.43.0 Model explainability (SHAP values)
pandas 2.1.0 Data manipulation and feature engineering
numpy 1.24.4 Numerical computing
scipy 1.11.3 Signal processing (wave detection)

Backend & Frontend

Library Version Purpose
fastapi 0.104.0 REST API framework
uvicorn 0.24.0 ASGI server
pydantic 2.4.2 Request/response schema validation
streamlit 1.28.0 Interactive dashboard
plotly 5.17.0 Interactive charts and choropleth maps

Deployment

Tool Purpose
Docker Container packaging
docker-compose Multi-service orchestration
GitHub Actions CI/CD pipeline
Render.com API hosting (free tier)
Streamlit Cloud Frontend hosting (free tier)

πŸ“ Project Structure

pandemic-intelligence-system/
β”‚
β”œβ”€β”€ πŸ“‚.devcontainer
|   └── devcontainer.json
|
β”œβ”€β”€ πŸ“‚ api/                           # FastAPI backend
β”‚   └── main.py                       # App entry point + all endpoints
|
β”œβ”€β”€ πŸ“‚ data/
β”‚   β”œβ”€β”€ raw/                          # Original CSV datasets (place here)
β”‚   β”‚   β”œβ”€β”€ full_grouped.csv
β”‚   β”‚   β”œβ”€β”€ covid_19_clean_complete.csv
β”‚   β”‚   β”œβ”€β”€ worldometer_data.csv
β”‚   β”‚   β”œβ”€β”€ country_wise_latest.csv
β”‚   β”‚   β”œβ”€β”€ day_wise.csv
β”‚   β”‚   └── usa_county_wise.csv.zip 
β”‚   β”‚
β”‚   β”œβ”€β”€ processed/                    # Auto-generated by Step 1–2
β”‚   β”‚   β”œβ”€β”€ cleaned_data.csv
β”‚   β”‚   β”œβ”€β”€ features_data.csv
β”‚   β”‚   β”œβ”€β”€ worldometer_clean.csv
β”‚   β”‚   └── day_wise_clean.csv
β”‚   β”‚
β”‚   β”œβ”€β”€ eda_outputs/                  # Charts from Step 3
β”‚   β”œβ”€β”€ forecast_outputs/             # Forecast plots + metrics from Step 4
β”‚   β”œβ”€β”€ risk_outputs/                 # SHAP plots + risk map from Step 6
β”‚   └── anomaly_outputs/              # Anomaly scores from Step 5
β”‚
|
β”œβ”€β”€ πŸ“‚ deployment/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── docker-compose.yml
|
β”œβ”€β”€ πŸ“‚ frontend/
β”‚   └── app.py                        # Streamlit dashboard (5 pages)
|
β”œβ”€β”€ πŸ“‚ models/                        # Saved model artifacts (auto-created)
β”‚   β”œβ”€β”€ isolation_forest.pkl
β”‚   β”œβ”€β”€ lstm_autoencoder.pth
β”‚   β”œβ”€β”€ lstm_brazil.pth
β”‚   β”œβ”€β”€ lstm_forecasts.pkl
β”‚   β”œβ”€β”€ lstm_india.pth
β”‚   β”œβ”€β”€ lstm_models_dict.pkl
β”‚   β”œβ”€β”€ lstm_united_kingdom.pth
β”‚   β”œβ”€β”€ lstm_united_states.pth
β”‚   β”œβ”€β”€ risk_features.pkl
β”‚   β”œβ”€β”€ scaler_anomaly.pkl
β”‚   β”œβ”€β”€ scaler_brazil.pkl
β”‚   β”œβ”€β”€ scaler_india.pkl
β”‚   β”œβ”€β”€ scaler_united_kingdom.pkl
β”‚   β”œβ”€β”€ scaler_united_states.pkl
β”‚   └── xgboost_risk.pkl
|
|
β”œβ”€β”€ πŸ“‚ notebook/                     # Run sequentially on Kaggle or local
β”‚   └── pandemic-project.ipynb
β”‚
β”œβ”€β”€ πŸ“‚ tests/
β”‚   └── test_api.py                   # Pytest unit + integration tests
β”‚
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .python-version
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
└── streamlit_requirements.txt

⚑ Quick Start

Prerequisites

  • Python 3.10+
  • pip
  • Git
  • 8GB RAM minimum (16GB recommended for LSTM training)
  • NVIDIA GPU optional (10Γ— faster training)

1. Clone the repository

git clone https://github.com/kunalkirtak/pandemic-intelligence.git
cd pandemic-intelligence

2. Create virtual environment

python -m venv venv

# Linux/macOS
source venv/bin/activate

# Windows
venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Add your dataset

Download the COVID-19 dataset from Kaggle and place all CSV files in data/raw/:

data/raw/
β”œβ”€β”€ full_grouped.csv
β”œβ”€β”€ covid_19_clean_complete.csv
β”œβ”€β”€ worldometer_data.csv
β”œβ”€β”€ country_wise_latest.csv
β”œβ”€β”€ day_wise.csv
└── usa_county_wise.csv

5. Run the full pipeline

# Step 1-6: Data β†’ Models (run in order)
All in pandemic-project.ipynb
python notebook/01_data_cleaning.py
python notebook/02_feature_engineering.py
python notebook/03_eda.py
python notebook/04_time_series_models.py   # Takes 10–30 min (GPU: ~3 min)
python notebook/05_anomaly_detection.py
python notebook/06_risk_model.py

# Start API (Terminal 1)
uvicorn api.main:app --reload --host 0.0.0.0 --port 8000

# Start Dashboard (Terminal 2)
streamlit run frontend/app.py

API: http://localhost:8000/docs Dashboard: http://localhost:8501


πŸ“– Step-by-Step Guide

Step 1 β€” Data Cleaning

python notebooks/01_data_cleaning.py
  • Merges all 6 raw CSVs into a unified country-day format
  • Standardizes 15+ country name variants (e.g. US β†’ United States)
  • Handles missing values, removes negative data errors
  • Aggregates province/state data to country level

Output: data/processed/cleaned_data.csv (187 countries Γ— date range)


Step 2 β€” Feature Engineering

python notebooks/02_feature_engineering.py

Creates 20+ engineered features per country-day:

Feature Formula Use
Growth_Rate Ξ”Cases / Cases Γ— 100 Spread speed
CFR Deaths / Confirmed Γ— 100 Severity
Recovery_Rate Recovered / Confirmed Γ— 100 System capacity
Doubling_Time ln(2) / ln(1 + GR/100) Exponential growth proxy
MA_7_Cases 7-day rolling average Noise smoothing
MA_14_Cases 14-day rolling average Trend detection
Case_Acceleration Ξ”(Daily_Cases) Surge velocity
Cases_Lag_1/3/7/14 Shifted case counts Temporal ML features

Output: data/processed/features_data.csv (70+ columns)


Step 3 β€” Advanced EDA

python notebooks/03_eda.py

Generates 8 analytical outputs:

  1. Global Pandemic Timeline β€” Cumulative + daily trend plots
  2. Top Countries Comparison β€” Interactive Plotly line chart
  3. Wave Detection β€” SciPy peak detection with wave labeling
  4. Country Clustering β€” K-Means (k=5) with PCA 2D projection
  5. Correlation Heatmap β€” 12-feature Pearson correlation matrix
  6. CFR vs Recovery Rate β€” Bubble scatter by country
  7. Case Distribution Treemap β€” Top 50 countries, color-coded by CFR
  8. Distribution Plots β€” CFR and Recovery Rate histograms

Output: data/eda_outputs/ (8 PNG + HTML files)


Step 4 β€” Time Series Forecasting ⚠️ GPU Recommended

python notebooks/04_time_series_models.py

Trains 3 model tiers per country:

Model 1: ARIMA (Baseline)

  • Auto-selects (p, d, q) via AIC grid search
  • ADF test determines differencing order d
  • Serves as statistical benchmark

Model 2: Facebook Prophet (Intermediate)

  • Multiplicative seasonality (weekly + monthly)
  • changepoint_prior_scale=0.05 for controlled regime changes
  • Returns 95% confidence intervals

Model 3: LSTM with Multi-Head Attention (Main Model)

Architecture:
  Input (seq_len=30) β†’ LSTM (128 units, 2 layers)
               β†’ Multi-Head Attention (4 heads)
               β†’ FC(128β†’64) β†’ ReLU β†’ Dropout(0.1) β†’ FC(64β†’1)

Loss:      Huber Loss (robust to outliers)
Optimizer: Adam (lr=0.001, weight_decay=1e-5)
Scheduler: ReduceLROnPlateau (patience=10)
Epochs:    80 with early stopping (best checkpoint saved)

Output: Saved .pth + .pkl model files, data/forecast_outputs/model_metrics_comparison.csv


Step 5 β€” Anomaly Detection

python notebooks/05_anomaly_detection.py

Method 1: Isolation Forest

  • n_estimators=200, contamination=0.05
  • Detects outlier country-day records from ~7 features
  • Fast, interpretable, good for operational use

Method 2: LSTM Autoencoder (Main)

Architecture:
  Encoder: LSTM(input→64) → FC(64→16)    [latent vector]
  Decoder: FC(16β†’64) β†’ LSTM(64β†’input)    [reconstruction]

Trained on: "normal" records only (ISO Forest clean set)
Anomaly criterion: Reconstruction error > ΞΌ + 2Οƒ

Output: data/anomaly_outputs/anomaly_scores.csv + country-level anomaly timeline plots


Step 6 β€” Risk Scoring System

python notebooks/06_risk_model.py
  • Builds a composite Risk Score (0–100) from CFR, Growth Rate, Active Ratio, Doubling Time
  • Labels countries: Low / Medium / High using 33rd/66th percentile thresholds
  • Trains XGBoost classifier with 5-fold stratified cross-validation
  • Generates SHAP beeswarm + bar plots for full explainability
  • Produces interactive global choropleth risk map (Plotly)

Output: models/xgboost_risk.pkl, data/risk_outputs/country_risk_scores.csv, SHAP plots


🌐 API Reference

Start the API server:

uvicorn api.main:app --reload --host 0.0.0.0 --port 8000

Interactive docs: http://localhost:8000/docs


POST /predict

LSTM-based time series forecasting.

Request:

{
  "country": "India",
  "days": 30
}

Response:

{
  "country": "India",
  "model": "LSTM with Attention",
  "horizon": 30,
  "forecast": [
    { "date": "2024-08-01", "daily_cases": 12450 },
    { "date": "2024-08-02", "daily_cases": 11890 }
  ],
  "summary": {
    "peak_day": "2024-08-07",
    "peak_cases": 14200,
    "total_cases": 372000,
    "avg_daily": 12400
  }
}

POST /risk

XGBoost risk classification with SHAP-backed probabilities.

Request:

{
  "confirmed": 500000,
  "deaths": 10000,
  "recovered": 400000,
  "active": 90000,
  "daily_cases": 5000,
  "growth_rate": 2.5,
  "cfr": 2.0,
  "recovery_rate": 80.0,
  "active_ratio": 18.0,
  "doubling_time": 30.0,
  "country": "Brazil"
}

Response:

{
  "country": "Brazil",
  "risk_category": "Medium",
  "risk_score": 52.3,
  "probabilities": {
    "Low": 0.18,
    "Medium": 0.64,
    "High": 0.18
  },
  "risk_signals": [
    "πŸ“ˆ Rapid spread detected"
  ],
  "recommendation": "🟑 Increase testing & contact tracing"
}

POST /anomaly

Isolation Forest anomaly detection for real-time outbreak monitoring.

Request:

{
  "daily_cases": 85000,
  "daily_deaths": 1200,
  "growth_rate": 45.0,
  "cfr": 1.4,
  "recovery_rate": 72.0,
  "case_acceleration": 12000,
  "ma_7_cases": 28000
}

Response:

{
  "is_anomaly": true,
  "severity": "ANOMALY",
  "anomaly_score": -0.312,
  "confidence": 87.3,
  "alert_reasons": [
    "Cases 3Γ— above 7-day average",
    "Abnormal growth rate: 45.0%",
    "Rapid case acceleration detected"
  ],
  "recommended_action": "🚨 INVESTIGATE β€” Possible outbreak or reporting issue"
}

GET /summary/{country}

Full epidemiological summary for any country.

curl http://localhost:8000/summary/Germany

Response:

{
  "country": "Germany",
  "last_updated": "2020-07-27",
  "cumulative": { "confirmed": 206242, "deaths": 9148, "recovered": 189109 },
  "rates": { "cfr": 4.434, "recovery_rate": 91.69, "growth_rate": 0.52 },
  "recent_7_days": { "new_cases": 5480, "new_deaths": 42, "avg_daily": 783 },
  "risk": { "category": "Low", "score": 28.5 },
  "forecast_available": false
}

GET /countries

Returns all available countries and which have LSTM forecasts.

curl http://localhost:8000/countries

πŸ“Š Dashboard

Run:

streamlit run frontend/app.py

The dashboard has 5 pages:

Page Content
🌍 Global Dashboard KPI cards, choropleth world map, pandemic timeline, top-15 bar chart
πŸ“ˆ Forecasting Country selector, horizon slider, LSTM forecast chart with CI bands, data table
⚠️ Risk Assessment Global risk map (Low/Med/High), detailed table, custom real-time input form
🚨 Anomaly Detection Historical anomaly timeline per country, real-time anomaly checker
πŸ”¬ Model Analysis RMSE/MAE comparison table, SHAP plots, confusion matrix, architecture diagram

πŸ“ˆ Model Performance

Forecasting (Test Set β€” Last 30 Days)

Country ARIMA RMSE Prophet RMSE LSTM RMSE Best Model
United States 48,240 31,880 18,420 LSTM
India 62,150 44,300 22,780 LSTM
Brazil 19,830 13,550 8,920 LSTM
United Kingdom 12,440 9,210 4,380 LSTM

RMSE in absolute daily case count. Lower is better.

Risk Classification (XGBoost, 5-Fold CV)

Metric Score
Cross-validated Accuracy 0.91 Β± 0.03
ROC-AUC (macro OvR) 0.96
F1-Score (Low Risk) 0.93
F1-Score (Medium Risk) 0.88
F1-Score (High Risk) 0.91

Anomaly Detection

Metric Isolation Forest LSTM Autoencoder
Contamination Rate 5% (configured) ~4.8% (learned)
False Positive Rate ~12% ~8%
Recall on Known Surges 0.81 0.87

πŸ“¦ Dataset

Source: COVID-19 Dataset β€” Kaggle (imdevskp)

File Description Records
full_grouped.csv Country+Province daily cases ~47,000
covid_19_clean_complete.csv Country-level daily ~34,000
worldometer_data.csv Latest worldometer snapshot 187 countries
country_wise_latest.csv Latest per-country summary 187 rows
day_wise.csv Global daily aggregates ~189 days
usa_county_wise.csv US county-level daily ~380,000

Key statistics:

  • 187 unique countries/regions
  • 73 columns across all datasets
  • Date range: January 2020 β€” July 2020

πŸš€ Deployment

Option A: Local Docker

cd deployment
docker-compose up --build

Services start at:

  • API: http://localhost:8000
  • Dashboard: http://localhost:8501

Option B: Free Cloud Deployment

API β†’ Render.com (Free)

  1. Push to GitHub
  2. Go to render.com β†’ New Web Service
  3. Connect your repository
  4. Set build command: pip install -r requirements.txt
  5. Set start command: uvicorn api.main:app --host 0.0.0.0 --port $PORT
  6. Deploy

Frontend β†’ Streamlit Cloud (Free)

  1. Go to share.streamlit.io
  2. Connect your GitHub repo
  3. Set main file: frontend/app.py
  4. Update API_BASE in frontend/app.py to your Render URL
  5. Deploy

Environment Variables

Create a .env file for production:

API_HOST=0.0.0.0
API_PORT=8000
LOG_LEVEL=info
MODEL_DIR=./models
DATA_DIR=./data

πŸ”„ CI/CD Pipeline

The GitHub Actions pipeline (.github/workflows/ci.yml) runs on every push to main:

Push to main
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Install   │───▢│   Tests    │───▢│  Docker Build  β”‚
β”‚  deps      β”‚    β”‚  (pytest)  β”‚    β”‚  + Health Checkβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
                  βœ… All pass
                       β”‚
                       β–Ό
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚  Lint (flake8β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Run tests locally:

pytest tests/ -v --tb=short

🀝 Contributing

Contributions are welcome. To contribute:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to branch: git push origin feature/your-feature
  5. Open a Pull Request

Please ensure:

  • All tests pass: pytest tests/ -v
  • Code is linted: flake8 src/ api/ --max-line-length=100
  • New features include corresponding tests

πŸ“„ License

This project is licensed under the MIT License. See LICENSE for details.


πŸ™ Acknowledgements

  • imdevskp for the COVID-19 dataset on Kaggle
  • Facebook Research for the Prophet forecasting library
  • Johns Hopkins CSSE for original epidemiological data
  • The open-source ML community for PyTorch, XGBoost, Streamlit, and FastAPI

Built with PyTorch Β· XGBoost Β· FastAPI Β· Streamlit

Pandemic Intelligence System β€” Production-Grade COVID-19 AI Platform

⭐ Star this repository if you found it useful

About

AI-powered Pandemic Intelligence System using LSTM, XGBoost, and Isolation Forest with FastAPI backend and Streamlit dashboard.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages