Repo

Bengaluru · Jan–Dec 2024 · CPCB and KSPCB daily AQI

The city AQI number is an average of places that have nothing in common.

News apps show one number for all of Bengaluru. On the same day, a traffic junction and a quiet residential road can be 80 AQI points apart, so that single number does not describe either of them.

I collected a year of daily readings from every station I could get a clean export for, worked out six numbers that describe each station's year, and then grouped the stations three different ways to see which ones keep coming out worst.

01Every station on the map

These are measured 2024 values. Circle colour is the station's average AQI for the year, and circle size is how much of the year it spent in unhealthy air. Click a station to see all six numbers I used.

colour by
Show all 13 stations as a table
Each station's 2024 numbers, worst average first.
Station Network Avg AQI Worst day Unhealthy days Weekly swing Winter avg Flagged by

02Three ways of grouping the stations

I ran K-Means, hierarchical clustering with Ward linkage, and DBSCAN on the same six features. They give different answers, and the differences are useful, so all three are here with their scores.

Higher silhouette and Calinski–Harabasz are better. Lower Davies–Bouldin is better.
Model Groups Left out Silhouette Davies–Bouldin Calinski–Harabasz Settings

Why I went with DBSCAN

DBSCAN has the best silhouette score at 0.475 and the best Davies–Bouldin at 0.597. The bigger reason is how it behaves. K-Means has to put every station into some group, so a station with extreme readings gets pulled into a broad “high” group and stops looking extreme. DBSCAN is allowed to leave a station out of every group, and it left out 8 of them. Those 8 are the ones I care about.

Hierarchical clustering scores better than DBSCAN on Calinski–Harabasz, 13.34 against 7.50. And with 13 stations and 6 features, all of these scores move around a lot. So I would defend the ranking of the stations, and I would not defend the exact number of groups.

03Stations more than one model flagged

The three methods make different assumptions, so a station that shows up in two or three of them is a stronger result than one that shows up in only one.

    RVCE-Mailasandra and Silk Board are the only two that all three methods agreed on. Silk Board is the station that hit 500, and it sits on a junction, which is roughly what you would guess before looking at any of this.

    04How I actually did it

    Most of the time went on cleaning the files. The clustering at the end was quick.

    1. Downloading the data

      The CPCB portal gives you one Excel file per station, laid out as a wide day-by-month grid. The layout is not the same between stations, so I had to reshape each file into a plain date-and-value list before any two stations could be compared.

    2. Dropping one station

      I downloaded 14 files and used 13. The Kadabesanahalli export only covers 2023, so including it would have meant comparing one station's 2023 against everyone else's 2024. The file is still in data/raw/ and the notebook drops it.

    3. Six numbers per station

      Average AQI, worst reading, share of days in unhealthy air, how much it swings week to week, winter average, and whether it trended up or down over the year. AQI and a trend slope are on completely different scales, so everything gets standardised before clustering.

    4. Running the three methods

      K-Means with the elbow method to pick the number of groups, hierarchical with Ward linkage, and DBSCAN with eps=0.940 and min_samples=2. I scored all three on the same metrics so I was not just picking whichever map looked nicest.

    5. Writing it up

      A ranked list of the worst stations, a map per method, and a combined view. Everything is in results/ and the notebook runs top to bottom.

    05Figures from the notebook

    Straight out of Air Quality Analysis.ipynb, unedited.

    06Where this falls short

    Have a look at the rest

    Data comes from the CPCB CAAQMS portal and KSPCB, both public. Analysis and figures are mine. MIT licensed.