This project is a FastAPI web application that predicts the Air Quality Index (PM) based on environmental features using a machine learning model trained with TPOT (Tree-based Pipeline Optimization Tool). The app provides a user-friendly web interface and an API endpoint for predicting PM values from input features: Average Annual Minimum Temperature (Tm
), Average Annual Temperature (T
), Sea Level Pressure (SLP
), Visibility (VV
), and Average Annual Maximum Temperature (TM
).
The application uses a TPOTRegressor
model trained on a dataset of environmental variables to predict the Air Quality Index (PM). The model was optimized using Repeated K-Fold cross-validation and saved using Python's pickle
module. The web interface is designed with a modern, responsive, and eye-catching blue-green theme, reflecting environmental concerns.
- Web Interface: A form to input
Tm
,T
,SLP
,VV
, andTM
and display the predicted PM. - API Endpoint: A RESTful API for programmatic predictions.
- Responsive Design: Mobile-friendly UI with a clean, environmental-themed style.
- Model: Optimized TPOT pipeline saved as
tpot_model.pkl
.
The model was trained on a dataset with the following features:
- Tm: Average annual minimum temperature (°C)
- T: Average annual temperature (°C)
- SLP: Sea level pressure (hPa)
- VV: Visibility (km)
- TM: Average annual maximum temperature (°C)
- PM: Air Quality Index (target variable, µg/m³)
Sample Data (for demonstration; actual dataset may be larger):
+-----+------+---------+-----+------+------------+
| Tm | T | SLP | VV | TM | PM |
+-----+------+---------+-----+------+------------+
| 4.8 | 7.4 | 1017.6 | 0.5 | 9.8 | 219.720833 |
| 4.4 | 7.8 | 1018.5 | 0.6 | 12.7 | 182.1875 |
| 2.4 | 6.7 | 1019.4 | 0.6 | 13.4 | 154.0375 |
| 3.3 | 8.6 | 1018.7 | 0.8 | 15.5 | 223.208333 |
| 4.4 | 12.4 | 1017.3 | 1.3 | 20.9 | 200.645833 |
+-----+------+---------+-----+------+------------+
air-quality-app/
├── main.py # FastAPI application
├── tpot_model.pkl # Trained TPOT model
├── templates/
│ └── index.html # HTML form for predictions
├── static/
│ └── style.css # CSS for styling the web interface
├── requirements.txt # Python dependencies
- Python 3.7+
- Git
- A web browser for the interface
- Optional: A cloud platform account (e.g., Render, Heroku) for deployment
- Clone the Repository:
git clone https://github.com/jarif87/tpot-driven-air-quality-modeling.git cd tpot-driven-air-quality-modeling
- Create a Virtual Environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install Dependencies:
pip install -r requirements.txt
- Contents of requirements.txt:
fastapi==0.115.13
Jinja2==3.1.6
numpy==1.26.4
pydantic==2.11.7
pandas==2.2.3
uvicorn==0.34.3
scikit-learn==1.2.2
python-multipart
uvicorn main:app