How asif3359/dengu_out_break_final_capstone works
Purpose and Entry Points
This repository is an end-to-end dengue outbreak risk prediction system for WHO SEARO countries. It supports offline data/model workflows, a Python REST inference service, and an interactive dashboard.
Primary entry points:
• Data preparation: data_preprocessing.py
• Classical model training/selection: train.py
• Experimental sequence-model training: train_lstm.py
• CLI inference: predict.py
• API application: backend/app/main.py
• Dashboard route: dashboard/src/app/page.tsx
Data Acquisition and Feature Pipeline
The training pipeline combines OpenDengue surveillance CSV data with NASA POWER weather observations. Country/year weather responses are persisted as Parquet cache files, avoiding repeated external API retrieval. Preprocessing produces the merged, feature-engineered training dataset, including temporal lags, rolling statistics, and cyclical fields.
Key boundaries:
• Source and generated datasets: data/filtered_data_SEARO_1769008875181.csv, data/merged_data.csv
• Cached meteorology: data/weather_cache/IND_1981_2025.parquet
• Pipeline implementation and training settings: data_preprocessing.py, config.py
Model Training and Artifact Contract
train.py evaluates classical classifiers and selects a serialized production model, described as XGBoost. It accounts for imbalance and tunes the decision threshold. train_lstm.py produces LSTM and Transformer artifacts as experimental alternatives; the API’s artifact contract is centered on the joblib model path.
Inference depends on a version-coupled artifact set:
• Classifier and preprocessing: models/model.joblib, models/scaler.joblib, models/encoder.joblib
• Feature ordering and serving metadata: models/feature_names.json, models/metadata.json
• Experimental deep-learning outputs: models/lstm_model.keras, models/transformer_model.keras
FastAPI Inference Service
The backend is a modular FastAPI application. backend/app/main.py initializes the application, versioned API routing, CORS, and service lifecycle. Request schemas constrain prediction payloads, while the predictor service loads artifacts, aligns/scales feature vectors, calculates probability, and applies the configured or metadata threshold.
Core service stages:
• Settings and shared dependencies: backend/app/core/config.py, backend/app/core/dependencies.py
• Request/response models: backend/app/models/schemas.py
• Artifact-backed inference: backend/app/services/predictor.py
• Public endpoints: backend/app/api/v1/endpoints/predict.py, backend/app/api/v1/endpoints/features.py, backend/app/api/v1/endpoints/health.py
The API exposes health status, required feature names, single prediction, and batch prediction. It is the authoritative boundary between browser clients and Python/ML artifacts.
Dashboard Client
The dashboard is a Next.js App Router application that gathers feature inputs, invokes the backend using NEXT_PUBLIC_API_URL, and renders results and interpretability-oriented visualizations. It does not host model logic; browser-to-API calls are its key runtime boundary.
Main client flow:
• Page composition: dashboard/src/app/page.tsx, dashboard/src/app/layout.tsx
• Form and result presentation: dashboard/src/components/PredictionForm.tsx, dashboard/src/components/ResultsDisplay.tsx
• Prediction state/API transport: dashboard/src/hooks/usePrediction.ts, dashboard/src/services/api.ts
• Supporting risk/history views: dashboard/src/components/FeatureImportance.tsx, dashboard/src/components/HistoryChart.tsx
Runtime and Deployment Boundaries
The backend targets Python 3.11+, FastAPI/Pydantic/Uvicorn, and XGBoost/scikit-learn artifacts. It is containerized independently; backend/docker-compose.yml and backend/Dockerfile define API deployment, including access to the repository-level models/ directory. Dashboard deployment is a separate Node.js/Next.js runtime.
External dependencies are limited to historical OpenDengue data and NASA POWER meteorological data during pipeline construction. Serving is artifact-local and should not require those external services. Backend configuration—including model locations, threshold fallback, and CORS origins—is centralized in backend/app/core/config.py and exposed through backend/.env.example.
Main entry points: data_preprocessing.py Feature pipeline · predict.py v1 endpoints · merged_data.csv Training dataset · model.joblib Serving artifact bundle
Components 20
Data & Training
Offline acquisition, feature engineering, and model selection.
- Surveillance & weather sources · OpenDengue CSV data and NASA POWER observations.
- Feature pipeline · Merges data and creates lags, rolling, and cyclical features.
data_preprocessing.py - Weather cache · Avoids repeated NASA POWER retrieval.
data/weather_cache/IND_1981_2025.parquet - Training dataset · Merged feature-engineered data.
data/merged_data.csv - Training settings
config.py - Classical model selection · Evaluates classifiers, handles imbalance, and tunes threshold.
train.py - Sequence-model experiments · Produces LSTM and Transformer alternatives.
train_lstm.py
Model Artifacts
Version-coupled files used by serving.
- Serving artifact bundle · Classifier, scaler, encoder, feature order, and metadata must remain aligned.
models/model.joblib - Experimental deep artifacts
models/lstm_model.keras - CLI inference
predict.py
Inference API
FastAPI boundary for artifact-backed predictions.
- FastAPI application · Initializes lifecycle, CORS, and versioned routing.
backend/app/main.py - Backend settings · Centralizes artifact locations, threshold fallback, and CORS.
backend/app/core/config.py - Prediction schemas · Constrains request and response payloads.
backend/app/models/schemas.py - Predictor service · Aligns and scales features, then applies probability threshold.
backend/app/services/predictor.py - v1 endpoints · Health, required features, single, and batch prediction.
backend/app/api/v1/endpoints/predict.py - API container deployment · Mounts or accesses repository model artifacts.
backend/Dockerfile
Dashboard
Separate Next.js browser runtime.
- Dashboard page · Composes the interactive prediction experience.
dashboard/src/app/page.tsx - Prediction UI · Collects inputs and renders risk results.
dashboard/src/components/PredictionForm.tsx - Prediction client · Calls the API using NEXT_PUBLIC_API_URL.
dashboard/src/hooks/usePrediction.ts - Risk & history views · Interpretability-oriented feature and history visualizations.
dashboard/src/components/FeatureImportance.tsx
Connections 22
- Surveillance & weather sources → Feature pipeline: retrieve input data
- Weather cache → Feature pipeline: reuse cached weather
- Feature pipeline → Weather cache: persist weather responses
- Feature pipeline → Training dataset: write engineered data
- Training settings → Feature pipeline: pipeline settings
- Training dataset → Classical model selection: train and evaluate
- Training settings → Classical model selection: training settings
- Training dataset → Sequence-model experiments: train experiments
- Classical model selection → Serving artifact bundle: serialize selected model
- Sequence-model experiments → Experimental deep artifacts: write Keras models
- Serving artifact bundle → CLI inference: load for local inference
- Backend settings → FastAPI application: configure app
- FastAPI application → v1 endpoints: register v1 routes
- v1 endpoints → Prediction schemas: validate payloads
- v1 endpoints → Predictor service: prediction requests
- Backend settings → Predictor service: model paths and threshold
- Serving artifact bundle → Predictor service: load artifacts
- API container deployment → FastAPI application: run service
- Dashboard page → Prediction UI: compose
- Prediction UI → Prediction client: submit inputs
- Prediction client → v1 endpoints: browser API calls · Health, features, single, and batch prediction.
- Prediction UI → Risk & history views: render result context