VOOZH about

URL: https://www.geeksforgeeks.org/python/predicting-air-quality-index-using-python/

⇱ Predicting Air Quality Index using Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Predicting Air Quality Index using Python

Last Updated : 27 May, 2025

Air pollution is a growing concern globally, and with increasing industrialization and urbanization, it becomes crucial to monitor and predict air quality in real-time. One of the most reliable ways to quantify air pollution is by calculating the Air Quality Index (AQI). In this article, we will explore how to predict AQI using Python, leveraging data science tools and machine learning algorithms.

What is AQI?

The Air Quality Index (AQI) is a standardized indicator used to communicate how polluted the air currently is or how polluted it is forecast to become. The AQI is calculated based on pollutants such as:

  • PM2.5
  • PM10
  • NO2
  • SO2
  • CO
  • O3

Each pollutant has a sub-index, and the highest sub-index among them becomes the AQI.

Where:

  • I is the AQI
  • C is the concentration of the pollutant
  • , are the breakpoint concentrations
  • , are the AQI values corresponding to those breakpoints

We can see how air pollution is by looking at the AQI

AQI LevelAQI Range
Good0 - 50
Moderate51 - 100
Unhealthy101 - 150
Unhealthy for Strong People151 - 200
Hazardous201+

Let's find the AQI based on Chemical pollutants using Machine Learning Concept. 

Data Set Description

It contains 7 attributes, of which 6 are chemical pollution quantities and one is Air Quality Index. AQI Value, CO AQI Value, Ozone AQI Value, NO2 AQI Value, PM2.5 AQI Value, lat,LNG are independent attributes. air_quality_index is a dependent attribute. Since air_quality_index is calculated based on the 7 attributes.

As the data is numeric and there are no missing values in the data, so no preprocessing is required. Our goal is to predict the AQI, so this task is either Classification or regression. So as our class label is continuous, regression technique is required.

Step-by-Step Process to Predict AQI

1. Importing Libraries

2. Loading the Dataset

We’ll use a dataset with pollutant concentration levels and corresponding AQI values.

3. Data Preprocessing

Handle missing values, rename columns, and check data types.

4. Exploratory Data Analysis (EDA)

Visualizing relationships between variables.

5. Feature Selection

Choose relevant features for training.

6. Train-Test Split

7. Model Training (Random Forest)

8. Model Evaluation

9. Plotting Results

Output:

👁 download-
Feature Correlation Map

Model Evaluation Metrics: Mean Absolute Error: 0.09 Mean Squared Error: 2.59 R2 Score: 1.00

👁 file
Predicted AQI

Real-world Applications

  • Smart cities to monitor pollution in real-time.
  • Healthcare apps to warn sensitive populations.
  • Environmental agencies for policy formulation.

Dataset Link: click here.

Comment
Article Tags: