CSC380 - Introduction to Data Science | Semester Project
University of Engineering and Technology, Lahore | Fall 2025
A comprehensive data science project analyzing global air quality measurements from major cities worldwide, featuring exploratory data analysis, machine learning model building, and actionable environmental recommendations.
- Overview
- Dataset Description
- Project Structure
- Features
- Installation
- Usage
- Analysis Pipeline
- Machine Learning Models
- Results
- Visualizations
- Key Findings
- Technologies Used
- Contributing
- License
Air pollution is a global concern affecting millions of people worldwide. This project analyzes the Global Air Quality Dataset containing 10,000 records of air quality measurements from various prominent cities worldwide. The analysis includes:
- Data Preprocessing & Cleaning - Handling missing values, outliers, and feature engineering
- Exploratory Data Analysis (EDA) - Comprehensive univariate, bivariate, and correlation analysis
- Machine Learning - Building and comparing classification models for AQI prediction
- Model Evaluation - Performance comparison with accuracy, precision, recall, and F1-score
- Recommendations - Strategies for environmental improvement
- Analyze air quality trends and patterns across different cities and countries
- Build predictive models for AQI (Air Quality Index) categories
- Understand the impact of pollution on health
- Suggest strategies for environmental improvement
| Feature | Description | Data Type |
|---|---|---|
| City | Name of the city | Object |
| Country | Country where city is located | Object |
| Date | Date of measurement | Object |
| PM2.5 | Fine particulate matter (Β΅g/mΒ³) | Float64 |
| PM10 | Coarse particulate matter (Β΅g/mΒ³) | Float64 |
| NO2 | Nitrogen dioxide (Β΅g/mΒ³) | Float64 |
| SO2 | Sulfur dioxide (Β΅g/mΒ³) | Float64 |
| CO | Carbon monoxide (mg/mΒ³) | Float64 |
| O3 | Ozone (Β΅g/mΒ³) | Float64 |
| Temperature | Temperature at measurement time (Β°C) | Float64 |
| Humidity | Humidity level (%) | Float64 |
| Wind Speed | Wind speed (m/s) | Float64 |
| Feature | Mean | Std Dev | Min | Max |
|---|---|---|---|---|
| PM2.5 | 77.45 | 41.93 | 5.02 | 149.98 |
| PM10 | 104.44 | 55.06 | 10.00 | 200.00 |
| NO2 | 52.20 | 27.32 | 5.01 | 100.00 |
| SO2 | 25.34 | 14.09 | 1.00 | 49.99 |
| CO | 5.05 | 2.85 | 0.10 | 10.00 |
| O3 | 106.03 | 55.08 | 10.04 | 200.00 |
| Temperature | 14.90 | 14.44 | -10.00 | 40.00 |
| Humidity | 55.08 | 25.98 | 10.01 | 99.99 |
| Wind Speed | 10.23 | 5.63 | 0.50 | 20.00 |
- Total Records: 10,000
- Cities Covered: 20
- Countries Covered: 19
- Date Range: January 1, 2023 to December 28, 2023
ids/
βββ air_quality_analysis.py # Main analysis script (971 lines)
βββ global_air_quality_data_10000.csv # Raw dataset
βββ cleaned_air_quality_data.csv # Preprocessed dataset
βββ model_results.csv # ML model performance results
βββ REPORT_CONTENT.txt # Detailed project report
βββ README.md # This file
βββ requirements.txt # Python dependencies
βββ figures/ # Generated visualizations
βββ 01_univariate_pollutants.png
βββ 02_univariate_meteorological.png
βββ 03_aqi_distribution.png
βββ 04_city_country_distribution.png
βββ 05_bivariate_pollutants_aqi.png
βββ 06_bivariate_meteo_aqi.png
βββ 07_boxplot_by_category.png
βββ 08_correlation_matrix.png
βββ 09_aqi_by_city.png
βββ 10_aqi_by_country.png
βββ 11_temporal_analysis.png
βββ 12_monthly_pollutant_trends.png
βββ 13_seasonal_city_comparison.png
βββ 14_pairplot.png
βββ 15_confusion_matrices.png
βββ 16_model_comparison.png
βββ 17_feature_importance.png
βββ 18_cv_scores.png
- β Missing value detection and handling (interpolation & mode imputation)
- β Outlier detection using IQR method
- β Outlier handling using Winsorization
- β Date parsing and temporal feature extraction (Year, Month, Day, Season, Quarter)
- β AQI calculation based on US EPA standards
- β Feature scaling (StandardScaler & MinMaxScaler)
- β Label encoding for categorical target variable
- π Univariate analysis of pollutants and meteorological variables
- π Bivariate analysis with scatter plots and trend lines
- π₯ Correlation matrix heatmap
- ποΈ Comparative analysis across cities and countries
- π Temporal/Seasonal trend analysis
- π² Random Forest Classifier
- π Gradient Boosting Classifier
- π Logistic Regression
- π― K-Nearest Neighbors (KNN)
- β‘ Support Vector Machine (SVM)
- Python 3.8 or higher
- pip (Python package installer)
- Clone the repository
git clone https://github.com/muhammad-rateeb/global-air-quality-analysis.git
cd global-air-quality-analysis- Create a virtual environment (recommended)
python -m venv .venv
# Windows
.venv\Scripts\activate
# Linux/Mac
source .venv/bin/activate- Install dependencies
pip install -r requirements.txtpython air_quality_analysis.pyThis will:
- Load and preprocess the dataset
- Perform comprehensive EDA
- Generate all visualizations in the
figures/folder - Train and evaluate 5 ML models
- Save results to
model_results.csv - Save cleaned data to
cleaned_air_quality_data.csv
graph TD
A[Raw Data] --> B[Data Loading]
B --> C[Missing Value Analysis]
C --> D[Outlier Detection & Handling]
D --> E[Feature Engineering]
E --> F[AQI Calculation]
F --> G[Feature Scaling]
G --> H[Train-Test Split 80:20]
H --> I[Model Training]
I --> J[Model Evaluation]
J --> K[Results & Recommendations]
| Step | Method | Description |
|---|---|---|
| Missing Values | Interpolation + Mode | Linear interpolation for numerical, mode for categorical |
| Outliers | IQR Method | Detection using Q1-1.5ΓIQR to Q3+1.5ΓIQR |
| Outlier Handling | Winsorization | Capping values at IQR bounds |
| Feature Scaling | StandardScaler | Z-score normalization |
| Train-Test Split | Stratified | 80% training, 20% testing |
| AQI Range | Category | Health Implication |
|---|---|---|
| 0 - 50 | Good | Air quality is satisfactory |
| 51 - 100 | Moderate | Acceptable; moderate concern for some |
| 101 - 200 | Unhealthy | Everyone may experience health effects |
| 201+ | Hazardous | Health alert; everyone affected |
- Random Forest Classifier - Ensemble of decision trees with bagging
- Gradient Boosting Classifier - Sequential ensemble with boosting
- Logistic Regression - Linear classification with regularization
- K-Nearest Neighbors - Instance-based learning
- Support Vector Machine - Kernel-based classification
| Model | Key Parameters |
|---|---|
| Random Forest | n_estimators=100, max_depth=None, random_state=42 |
| Gradient Boosting | n_estimators=100, learning_rate=0.1 |
| Logistic Regression | max_iter=1000, multi_class='multinomial' |
| KNN | n_neighbors=5, metric='minkowski' |
| SVM | kernel='rbf', C=1.0 |
| Model | Train Accuracy | Test Accuracy | Precision | Recall | F1-Score | CV Mean | CV Std |
|---|---|---|---|---|---|---|---|
| Random Forest | 100% | 99.9% | 99.85% | 99.9% | 99.87% | 99.89% | 0.07% |
| Gradient Boosting | 100% | 99.9% | 99.85% | 99.9% | 99.87% | 99.93% | 0.05% |
| Logistic Regression | 95.61% | 96.15% | 95.84% | 96.15% | 95.91% | 95.43% | 0.41% |
| KNN | 94.0% | 89.1% | 88.87% | 89.1% | 88.93% | 89.44% | 0.49% |
| SVM | 97.51% | 97.15% | 97.06% | 97.15% | 97.09% | 96.11% | 0.39% |
- Random Forest and Gradient Boosting achieved the highest accuracy (99.9%)
- Both models showed excellent generalization with minimal overfitting
- Cross-validation confirmed consistent performance
The project generates 18 comprehensive visualizations:
π Click to see visualization descriptions
| Figure | Description |
|---|---|
| 01_univariate_pollutants.png | Distribution histograms of all 6 pollutants |
| 02_univariate_meteorological.png | Distribution of temperature, humidity, wind speed |
| 03_aqi_distribution.png | AQI histogram and category bar chart |
| 04_city_country_distribution.png | Record counts by city and country |
| 05_bivariate_pollutants_aqi.png | Scatter plots: pollutants vs AQI with trend lines |
| 06_bivariate_meteo_aqi.png | Scatter plots: meteorological variables vs AQI |
| 07_boxplot_by_category.png | Box plots of pollutants by AQI category |
| 08_correlation_matrix.png | Heatmap of feature correlations |
| 09_aqi_by_city.png | Average AQI comparison across cities |
| 10_aqi_by_country.png | Average AQI comparison across countries |
| 11_temporal_analysis.png | Monthly AQI trends over time |
| 12_monthly_pollutant_trends.png | Monthly pollutant concentration patterns |
| 13_seasonal_city_comparison.png | Seasonal AQI variations by city |
| 14_pairplot.png | Pairwise relationships between features |
| 15_confusion_matrices.png | Confusion matrices for all 5 models |
| 16_model_comparison.png | Performance metrics comparison chart |
| 17_feature_importance.png | Random Forest feature importance |
| 18_cv_scores.png | Cross-validation score comparison |
- PM2.5 shows the strongest correlation with AQI
- Ozone (O3) levels vary significantly with temperature
- CO concentrations are relatively stable across regions
- Major industrial cities show consistently higher AQI values
- Coastal cities benefit from better air dispersion
- Seasonal patterns differ between hemispheres
- Ensemble methods (Random Forest, Gradient Boosting) significantly outperform other models
- Feature importance reveals PM2.5, PM10, and O3 as top predictors
- All models show good generalization with stratified sampling
- π Reduce vehicle emissions in urban areas
- π Implement stricter industrial emission controls
- π³ Increase green spaces and urban forests
- π Establish real-time air quality monitoring systems
- π Public awareness campaigns on air quality impacts
| Category | Technologies |
|---|---|
| Language | Python 3.x |
| Data Processing | Pandas, NumPy |
| Visualization | Matplotlib, Seaborn |
| Machine Learning | Scikit-learn |
| IDE | VS Code / Jupyter Notebook |
pandas # Data manipulation and analysis
numpy # Numerical computing
matplotlib # Static visualizations
seaborn # Statistical visualizations
scikit-learn # Machine learning algorithmsContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Muhammad Rateeb
- GitHub: @muhammad-rateeb
- University: University of Engineering and Technology, Lahore
- Course: CSC380 - Introduction to Data Science
- Dataset: Kaggle - Global Air Quality Dataset
- University of Engineering and Technology, Lahore
- CSC380 Course Instructors
Made with β€οΈ for Data Science