The Wayback Machine - https://web.archive.org/web/20241001064543/https://www.geeksforgeeks.org/predicting-air-quality-index-using-python/
Open In App

Predicting Air Quality Index using Python

Last Updated : 16 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Let us see how to predict the air quality index using Python. AQI is calculated based on chemical pollutant quantity. By using machine learning, we can predict the AQI.

AQI: The air quality index is an index for reporting air quality on a daily basis.  In other words, it is a measure of how air pollution affects one’s health within a short time period. The AQI is calculated based on the average concentration of a particular pollutant measured over a standard time interval. Generally, the time interval is 24 hours for most pollutants, and 8 hours for carbon monoxide and ozone.

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.

Regression is supervised learning technique that fits the data in a given range. Example Regression techniques in Python:

  • Random Forest Regressor
  • Ada Boost Regressor
  • Bagging Regressor
  • Linear Regression etc.
Python
# importing pandas module for data frame
import pandas as pd

# loading dataset and storing in train variable
train= pd.read_csv("/content/AQI and Lat Long of Countries.csv")
# display top 5 data
train.head()

 Output:

Screenshot-from-2024-09-04-10-23-07


Python
from sklearn.ensemble import RandomForestRegressor, AdaBoostRegressor

#CREATING MODEL
m1= RandomForestRegressor()


train1= train.drop(['AQI Value'], axis=1)

target= train['AQI Value']

print(train1)
print(target)
#FITTING THE MODEL
m1.fit(train1, target)

m1.score(train1, target)*100

# predicting the model with other values (testing the data)
prediction_result= m1.predict([[1, 10, 5, 11, 10, 5]])

print(prediction_result)


# Adaboost model
# importing module

from sklearn.ensemble import AdaBoostRegressor


# defining model
m2 = AdaBoostRegressor()

# Fitting the model
m2.fit(train1, target)

'''AdaBoostRegressor(base_estimator=None, learning_rate=1.0, loss='linear',
                  n_estimators=50, random_state=None)'''

m2.score(train1, target)*100

# predicting the model with other values (testing the data)
# so AQI is 48.73051389
m2.predict([[1, 45, 67, 34, 5, 23]])

Linear Regression:

Adaboost:


By this, we can say that by given test data we got 9.9 and 46.5952 so the air is healthy.

Get the complete notebook link here

Colab Link : click here.

Dataset Link : click here.


Previous Article
Next Article

Similar Reads

Predicting Air Quality with Neural Networks
Air Pollution is the most harmful pollution of all. It is a threat to human health and our environment. Understanding and predicting air quality is crucial to protecting the public's well-being and saving the environment. By using advanced technologies, we can better understand how pollution affects us and our planet, and take steps to keep the air
6 min read
Build an GUI Application to Get Live Air Quality Information Using Python.
We are living in a modernization and industrialization era. Our life becomes more and more convenient. But the problem is Air Pollution arise with time. This Pollution makes us unhealthy, Air is a Lifeline for our life. In this article, we are going to write python scripts to get live air quality information and bind it with GUI Application. Module
5 min read
Time Series Forecasting for Predicting Store Sales Using Prophet
Time series forecasting is a crucial aspect of business analytics, enabling companies to predict future trends based on historical data. Accurate forecasting can significantly impact decision-making processes, inventory management, and overall business strategy. One of the powerful tools for time series forecasting is Prophet, an open-source librar
10 min read
Predicting the Authenticity of Android Applications Using Classification Techniques
With the exponential growth of Android applications on the Google Play Store, ensuring the legitimacy and safety of these apps has become increasingly important. In this article, we discussed about predicting the authenticity of Android applications using classification techniques. With the increasing number of applications available on the Google
7 min read
Predicting Stock Price Direction using Support Vector Machines
We are going to implement an End-to-End project using Support Vector Machines to live Trade For us. You Probably must have Heard of the term stock market which is known to have made the lives of thousands and to have destroyed the lives of millions. If you are not familiar with the stock market you can surf some basic Stuff about markets. Tools and
5 min read
Predicting Loan Default in R
Predicting loan default is a common task in the financial industry and can be approached using various machine learning techniques in R. In today's world, people are somehow dependent on loans. Banks get their major income through loans and also it is the major source of financial risk for banks. People take loans for so many reasons like education
7 min read
Machine Learning for Predicting Geological Disasters
Using Machine Learning for the Prediction of Geological Disasters is a new idea that involves the use of sophisticated computer algorithms to analyze data large enough to find patterns that are characteristic of geological disasters. Combining data from some of the sources including seismic data, climate data, and geophysical data from other survey
6 min read
PECBO Analysis: Predicting Environmental Conditions from Biological Observations
Predicting environmental conditions from biological observations (PECBO) is an innovative approach that leverages biological data to infer environmental parameters. This method is particularly useful in areas where direct environmental measurements are challenging to obtain. By understanding the relationships between biological taxa and their envir
6 min read
AlphaFold: Predicting Protein Structures with Deep Learning
AlphaFold is an AI-driven system developed by DeepMind to predict protein structures with high accuracy. Its various iterations have been part of the continuous improvement in computational biology. Proteins are essential molecules in living organisms, involved in virtually every process within cells. The shape of a protein determines its function,
6 min read
Minimum index i such that all the elements from index i to given index are equal
Given an array arr[] of integers and an integer pos, the task is to find the minimum index i such that all the elements from index i to index pos are equal. Examples: Input: arr[] = {2, 1, 1, 1, 5, 2}, pos = 3 Output: 1 Elements in index range [1, 3] are all equal to 1. Input: arr[] = {2, 1, 1, 1, 5, 2}, pos = 5 Output: 5 Brute Force Approach: A br
12 min read
Calculate extra cost to be paid for luggage based on weight for Air travel
Given an array weight[] of size N containing weights of luggage. If the weights are within a threshold of W then it does not require any extra cost. But after the weights cross the threshold they need to pay extra cost according to the following table. The task is to calculate the extra cost of the luggage required. Range of exceeding weight Cost f
6 min read
Incedo Inc. Interview Experience for SDE/Quality Assurance Engineer | On-Campus
Incedo Inc. visited our college, SRM Institute of Science and Technology in August'21, and everything was conducted in virtual mode. I applied for the role of Software Development Engineer. While applying for the same we were asked to choose a programming language from C, C++, Java, and Python. I chose C++. There were 3 rounds in the whole process.
4 min read
Does batch_size in Keras have any effects in results' quality?
Answer: Yes, batch size in Keras can affect the model's training stability, convergence speed, and generalization ability, potentially influencing the results' quality.In Keras, as in other deep learning frameworks, the batch size—the number of training samples processed before the model is updated—plays a critical role in the training process and
2 min read
What is Data Quality and Why is it Important?
The significance of data quality in today's data-driven environment is quite impossible to emphasize. The quality of data becomes more crucial when organizations, businesses and individuals depend more and more on it for their work. This article gives detailed idea of what is data quality? its importance, and the essential procedures for making sur
7 min read
Data Quality Management - Definition, Importance
In this age, Data plays an important role. Every click, every transaction, and every interaction generates some data. But what happens when this information is inaccurate, incomplete, or inconsistent? This is where Data Quality Management (DQM) comes in. Let’s explore Data Quality Management and understand its importance in today’s world. Table of
10 min read
Data Lineage: A Comprehensive Guide to Enhancing Data Quality, Compliance, and Governance
In today's data-driven world, organizations are inundated with vast amounts of data flowing through various systems and processes. Amidst this complexity, ensuring data quality, compliance, and transparency has become paramount. Enter data lineage – a powerful concept that provides organizations with a detailed understanding of how data moves throu
6 min read
How to Get an Internship as a Data Quality Analyst
Securing an internship as a Data Quality Analyst is a crucial step towards a data management and analysis career. This role involves ensuring data accuracy, consistency, and reliability, which is essential for informed decision-making within organizations. Aspiring Data Quality Analysts must develop technical skills in SQL, Python, and data tools,
6 min read
Wine Quality Prediction - Machine Learning
Here we will predict the quality of wine on the basis of given features. We use the wine quality dataset available on Internet for free. This dataset has the fundamental features which are responsible for affecting the quality of the wine. By the use of several Machine learning models, we will predict the quality of the wine. Importing libraries an
5 min read
How Can I Extract a Good Quality JPEG Image From a Video File With ffmpeg?
Extracting individual frames from a video can be useful in many situations, such as creating thumbnails, analyzing specific frames, or saving still images from a video. One of the most popular tools for this task is ffmpeg, a powerful command-line utility for processing multimedia files. In this article, we will guide you on how to extract a high-q
3 min read
Check if every index i has an index j such that sum of elements in both directions are equal
Given a circular array of size N. The task is to check if, for every index, i starting from 0 to N-1, there exists an index j that is not equal to i such that the sum of all the numbers in the clockwise direction from i to j is equal to the sum of all numbers in the anticlockwise direction from i to j. Examples: Input: a[] = {1, 4, 1, 4} Output: Ye
6 min read
Difference between Inverted Index and Forward Index
Inverted Index It is a data structure that stores mapping from words to documents or set of documents i.e. directs you from word to document.Steps to build Inverted index are:Fetch the document and gather all the words.Check for each word, if it is present then add reference of document to index else create new entry in index for that word.Repeat a
2 min read
Number of permutations such that sum of elements at odd index and even index are equal
Given N numbers, find the number of permutations in which the sum of elements at odd index and sum of elements at even index are equal. Examples: Input: 1 2 3 Output: 2 The permutations are: 1 3 2 sum at odd index = 1+2 = 3, sum at even index = 3 2 3 1 sum at odd index = 2+1 = 3, sum at even index = 3 Input: 1 2 1 2 Output: 3 The permutations are:
8 min read
Dunn index and DB index - Cluster Validity indices | Set 1
Different performance metrics are used to evaluate different Machine Learning Algorithms. In case of classification problem, we have a variety of performance measure to evaluate how good our model is. For cluster analysis, the analogous question is how to evaluate the “goodness” of the resulting clusters? Why do we need cluster validity indices ? T
4 min read
Silhouette Index – Cluster Validity index | Set 2
Prerequisite: Dunn index and DB index – Cluster Validity indices Many interesting algorithms are applied to analyze very large datasets. Most algorithms don't provide any means for its validation and evaluation. So it is very difficult to conclude which are the best clusters and should be taken for analysis. There are several indices for predicting
3 min read
Queries for number of distinct elements from a given index till last index in an array
Given a array ‘a[]’ of size n and number of queries q. Each query can be represented by a integer m. Your task is to print the number of distinct integers from index m to n i.e till last element of the array. Examples: Input: arr[] = {1, 2, 3, 1, 2, 3, 4, 5}, q[] = {1, 4, 6, 8} Output: 5 5 3 1 In query 1, number of distinct integers in a[0...7] is
6 min read
Check if it is possible to reach to the index with value K when start index is given
Given an array arr[] of N positive integers and two positive integers S and K, the task is to reach the position of the array whose value is K from index S. We can only move from current index i to index (i + arr[i]) or (i – arr[i]). If there is a way to reach the position of the array whose value is K then print "Yes" else print "No". Examples: In
15+ min read
Farthest index that can be reached from the Kth index of given array by given operations
Given an array arr[] consisting of N integers and three integers X, Y, and K, the task is to find the farthest index that can be reached by the following operations: If arr[i] ? arr[i + 1]: Move from index i to i + 1.If arr[i] < arr[i+1]: Either decrement X by 1 if the value of X > 0 or decrement Y by (arr[i + 1] - arr[i]) if the value of Y
7 min read
Queries to calculate sum of array elements present at every Yth index starting from the index X
Given an array arr[] of size N, and an array Q[][] with each row representing a query of the form { X, Y }, the task for each query is to find the sum of array elements present at indices X, X + Y, X + 2 * Y + ... Examples: Input: arr[] = { 1, 2, 7, 5, 4 }, Q[][] = { { 2, 1 }, { 3, 2 } } Output: 16 5 Explanation: Query1: arr[2] + arr[2 + 1] + arr[2
15+ min read
Minimum count of indices to be skipped for every index of Array to keep sum till that index at most T
Given an array, arr[] of size N and an integer T. The task is to find for each index the minimum number of indices that should be skipped if the sum till the ith index should not exceed T. Examples: Input: N = 7, T = 15, arr[] = {1, 2, 3, 4, 5, 6, 7}Output: 0 0 0 0 0 2 3 Explanation: No indices need to be skipped for the first 5 indices: {1, 2, 3,
8 min read
Count of pass required to visit same index again by moving arr[i] to index arr[i]
Given an array(1-based indexing) arr[] of permutation of the first N natural numbers, the task for each element is to find the number of moves required to reach that index such that in each move, array element at index i moves to the array element at index arr[i]. Examples: Input: arr[] = {2, 3, 1}Output: 3 3 3 Explanation:For array element arr[1]
6 min read