Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Scrape Content from Dynamic Websites
Next article icon

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 theAir 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?

TheAir 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:

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

I = \frac{I_{HI} - I_{LO}}{BP_{HI} - BP_{LO}} \times (C - BP_{LO}) + I_{LO}

Where:

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,regressiontechnique is required.

Step-by-Step Process to Predict AQI

1.Importing Libraries

Python
importpandasaspdimportnumpyasnpimportmatplotlib.pyplotaspltimportseabornassnsfromsklearn.model_selectionimporttrain_test_splitfromsklearn.linear_modelimportLinearRegressionfromsklearn.ensembleimportRandomForestRegressorfromsklearn.metricsimportmean_absolute_error,mean_squared_error,r2_score

2.Loading the Dataset

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

Python
data=pd.read_csv('air_quality_data.csv')print(data.head())

3.Data Preprocessing

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

Python
data=data.dropna()data.columns=[col.strip().lower()forcolindata.columns]

4.Exploratory Data Analysis (EDA)

Visualizing relationships between variables.

Python
sns.pairplot(data)plt.show()corr=data.corr()sns.heatmap(corr,annot=True,cmap='coolwarm')

5.Feature Selection

Choose relevant features for training.

Python
X=data[['co aqi value','ozone aqi value','no2 aqi value','pm2.5 aqi value']]y=data['aqi value']

6.Train-Test Split

Python
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)

7.Model Training (Random Forest)

Python
model=RandomForestRegressor(n_estimators=100,random_state=42)model.fit(X_train,y_train)

8.Model Evaluation

Python
y_pred=model.predict(X_test)print("Mean Absolute Error:",mean_absolute_error(y_test,y_pred))print("Mean Squared Error:",mean_squared_error(y_test,y_pred))print("R2 Score:",r2_score(y_test,y_pred))

9.Plotting Results

Python
plt.figure(figsize=(10,6))plt.plot(y_test.values,label='Actual AQI')plt.plot(y_pred,label='Predicted AQI',alpha=0.7)plt.title('Actual vs Predicted AQI')plt.legend()plt.show()

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.


Predicting the Air Quality Index using Python
Video Thumbnail

Predicting the Air Quality Index using Python

Video Thumbnail

Air Quality Index Prediction in Machine Learning using Python

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp