A complete machine learning project for predicting and classifying C6H6 (Benzene) gas concentration using the AirQualityUCI dataset collected in Italy between March 2004 and February 2005.
├── air-Quality.ipynb # Main notebook
└── README.md
- Regression : Predict the continuous concentration of C6H6(GT) from air quality sensor data
- Binary Classification : Classify C6H6 levels as Low / High
- Multi-class Classification : Classify C6H6 levels as Low / Medium / High
This project is a comprehensive analysis of air quality data from the AirQualityUCI dataset (UCI Machine Learning Repository), collected in Italy between March 2004 and February 2005. The main objective is to predict and classify the concentration of C6H6 (Benzene) gas using data from chemical sensors and environmental measurements.
The raw dataset presented several quality issues: missing values encoded as -200, unusable columns, incorrect data types, and duplicates. A complete cleaning pipeline was implemented including:
- Removal of non-exploitable variables (
NMHC(GT), empty columns) - Date/time conversion and parsing
- Extraction of temporal features (year, month, day, hour, minute, second)
- Replacement of aberrant values with
NaNand imputation via linear interpolation - Duplicate removal
- StandardScaler normalization to homogenize feature scales
An in-depth visual exploration was conducted using distribution histograms, a correlation matrix (heatmap), boxplots for outlier detection, and a skewness analysis of feature distributions.
Three supervised regression models were trained to predict the continuous C6H6 concentration:
- Linear Regression
- Support Vector Regression (SVR)
- Random Forest Regressor
Models were evaluated using R², RMSE, and MAE metrics, compared on train/test sets, and benchmarked in terms of training and prediction time.
The target variable was discretized into two classes (Low / High) based on the median. Four classification algorithms were applied:
- Naive Bayes
- SVM (SVC)
- K-Nearest Neighbors (KNN)
- Decision Tree (with decision boundary visualization using PCA 2D)
Each model was evaluated via a classification report, a confusion matrix, and a ROC curve with AUC score.
A finer segmentation into three levels (Low / Medium / High) was performed using 33rd and 66th percentile thresholds. The SVM model with RBF kernel was used with a full multi-class evaluation including a per-class ROC curve and a 2D PCA projection to visualize class separation in a reduced space.
| Model | R² | RMSE | MAE |
|---|---|---|---|
| Linear Regression | 0.9849 | 0.1243 | 0.0852 |
| Random Forest | 0.9997 | 0.0183 | 0.0047 |
| SVR | 0.9951 | 0.0710 | 0.0416 |
Insight: Random Forest achieved the best performance with near-perfect R² and minimal error, indicating strong non-linear modeling capability.
| Model | Train Accuracy | Test Accuracy | F1-score (weighted) |
|---|---|---|---|
| Decision Tree | 1.00 | 1.00 | 1.00 |
| K-Nearest Neighbors | 0.97 | 0.96 | 0.96 |
| SVM | 0.98 | 0.98 | 0.98 |
| Naive Bayes | 0.92 | 0.91 | 0.91 |
Insight: Decision Tree achieved perfect accuracy for binary classification, while SVM and KNN also performed very well. Naive Bayes showed slightly lower performance but remains solid.
| Model | Train Accuracy | Test Accuracy | F1-score (weighted) |
|---|---|---|---|
| SVM | 0.97 | 0.96 | 0.96 |
- Feature distribution histograms
- Correlation matrix heatmap
- Boxplots for outlier detection
- ROC curves + AUC scores per model
- Confusion matrices
- Real vs Predicted scatter plots
- Model performance comparison (bar chart)
- 2D PCA projection of classes
- PCA visualization
Open air-quality.ipynb directly in Google Colab.
Upload AirQualityUCI.csv to your Colab session or mount your Google Drive.
Go to Runtime → Run all
Available at UCI ML Repository — Air Quality
| Category | Tools |
|---|---|
| Language | Python 3 |
| Data Manipulation | pandas, numpy |
| Visualization | matplotlib, seaborn |
| Machine Learning | scikit-learn |
| Environment | Google Colab |
- Source : UCI Machine Learning Repository — Air Quality
- Features : CO, NOx, NO2, C6H6, O3, Temperature, Relative Humidity, Absolute Humidity, PT08.S1–S5 sensors