← all projects
Case study · production ML

CivicLens
public data, honestly handled.

Can public environmental data predict road-accident risk in Indian cities? An end-to-end system — ingestion → warehouse → ablation-tested models → explainable predictions — built to look like production, not a notebook.

Live dashboard ↗ Live API docs ↗ Repository ↗
596K
ENV. RECORDS
453
CPCB STATIONS
37
STATES
3×3
ABLATION STUDY
78.3%
BEST CV ACC.
CivicLens dashboard overview showing city risk snapshot for 2024 across six Indian cities
The live dashboard — city snapshot with total accidents and latest model risk assessment per city.

01 · The problem

India records hundreds of thousands of road accidents every year, and government agencies publish rich open data — CPCB environmental monitoring, MoRTH accident statistics — that mostly sits unused. The question: does environmental data (rainfall, pollution, temperature, wind) carry a real predictive signal for city-level accident risk? And can that be answered with production-grade engineering rather than a one-off notebook?

The honest answer mattered more than an impressive one. Which meant: quality-scored data, leakage-safe validation, an ablation study to isolate where predictive power actually comes from, and per-prediction explainability.

02 · Architecture

Three public datasets flow through a layered PostgreSQL warehouse into cross-validated models, served by an API and a dashboard — one command to deploy, CI on every push.

CPCB environmental data596K records · 453 stations
MoRTH accident datastate & city level
City metadatageography · population
INGESTION + VALIDATION
PostgreSQL warehouseraw → clean → analytics · per-row quality scoring
FEATURE ENGINEERING · YoY changes · monsoon share · accident history
3×3 ablation studyLogReg · Random Forest · XGBoost
Best model + SHAPper-prediction explainability
SERVING
FastAPI servicelive on Render
7-tab Streamlit dashboardlive on Streamlit Cloud
Docker + GitHub Actionsone-command deploy · CI

03 · The anomaly that proved the pipeline

While validating the seasonal anomaly detector (city-months deviating sharply from that city's historical pattern, |z| > 2.5), it flagged Chennai's entire 2019 with 10–20× normal rainfall. One problem: 2019 was Chennai's famous "Day Zero" drought year.

Investigating led to station TN004 — a newly installed CPCB monitor whose faulty rain gauge reported ~20× the city's real annual rainfall for a year, then flatlined to exactly 0.0. A classic sensor failure. It was excluded and documented, and once removed, real events — like Pune's record 2019–20 unseasonal rains — became clearly visible in the data.

Anomalies tab showing 37 detected anomalies, Pune as most affected city, and z-score table of unusual environmental readings
The Anomalies tab — 37 statistically significant city-months. Some are real events (Pune's record rains); one was the TN004 data-quality catch.

04 · Results — reported honestly

Three feature configurations, identical cross-validation, three model families. The point of the ablation wasn't to maximize a headline number — it was to answer what actually predicts accident risk?

CONFIGURATIONFEATURESLOGREGRFXGBOOST
A · Baseline environment60.6710.6300.603
B · Enriched environment (no history)90.6000.7250.675
C · Full (env + accident history)110.6520.7390.783 ★

Best model: XGBoost on the full configuration at 78.3% cross-validated accuracy. But the ablation tells the real story: much of that performance comes from accident persistence — environmental conditions carry a real but secondary signal. That insight is worth more than a bigger number.

Model insights tab showing the 3x3 ablation study table and cross-validated accuracy bar chart
Model Insights — the 3×3 ablation, live in the dashboard.
Per-prediction SHAP chart for Delhi showing prev_total_accidents as the dominant feature
Per-prediction SHAP — every risk call shows exactly which features pushed it, per city.

05 · Lessons learned

Most of the work isn't training the model.

It's understanding the data and building reliable systems around it — the warehouse, quality scoring and validation took far more engineering than the models did.

An anomaly detector that can't catch a broken sensor can't be trusted on weather.

The TN004 catch was the moment the pipeline proved it worked — on data quality first, science second.

Ablations beat leaderboards.

Reporting 78.3% alone would have been misleading. Showing where the signal comes from — accident history first, environment second — is the finding.