Skip to content

ayushsingh08-ds/zephra-ml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌬️ Zephra ML - AQI Forecasting Service

Deploy to Render

A production-ready machine learning service for forecasting Air Quality Index (AQI) values using gradient boosting regression.

πŸš€ Features

  • βœ… Real-time Data: Fetches live data from Zephra API
  • 🧠 ML Model: Gradient Boosting Regressor with robust error handling
  • πŸ“Š Forecasting: Single-hour and 24-hour AQI predictions
  • 🌐 REST API: FastAPI with CORS support and health checks
  • 🐳 Docker Ready: Containerization for easy deployment
  • ☁️ Render Deploy: One-click deployment to Render platform

πŸ“ Project Structure

zephra-ml/
β”œβ”€β”€ data/                   # (optional) store local datasets if needed
β”œβ”€β”€ models/
β”‚   └── gbr_model.pkl       # trained model
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ data_loader.py      # fetch from /api/dashboard
β”‚   β”œβ”€β”€ train.py            # training + save model
β”‚   └── forecast.py         # 24h recursive forecast
β”œβ”€β”€ api/
β”‚   └── app.py              # FastAPI/Flask app
β”œβ”€β”€ requirements.txt        # dependencies
β”œβ”€β”€ Dockerfile              # for deployment
β”œβ”€β”€ run.sh                  # deployment script
└── README.md               # usage instructions

πŸ› οΈ Setup & Installation

Prerequisites

  • Python 3.9+
  • pip

Installation

  1. Clone or download the project
  2. Install dependencies:
    pip install -r requirements.txt

Quick Start

For Windows:

.\run.bat

For Linux/Mac:

./run.sh

This will automatically:

  1. Install all dependencies
  2. Train the model with fresh data from the Zephra API
  3. Start the API server on http://localhost:8080

Test the API:

python test_api.py

πŸ”§ Usage

Training the Model

First, train the model with the latest data:

python src/train.py

This will:

  • Fetch data from the Zephra API
  • Train a Gradient Boosting Regressor
  • Save the model to models/gbr_model.pkl
  • Display training RMSE

Running the API

Local Development

uvicorn api.app:app --host 0.0.0.0 --port 8080 --reload

Using Docker

docker build -t zephra-ml .
docker run -p 8080:8080 zephra-ml

One-Command Deployment

Use the provided script:

./run.sh

πŸ“‘ API Endpoints

GET /

Returns API information and version.

GET /predict

Returns AQI prediction for the next hour.

Response:

{
  "next_hour_AQI": 85.3
}

GET /forecast

Returns 24-hour AQI forecast.

Response:

{
  "forecast_24h": [85.3, 87.1, 89.2, ...]
}

πŸ”„ Model Details

  • Algorithm: Gradient Boosting Regressor
  • Parameters:
    • n_estimators: 200
    • learning_rate: 0.05
    • max_depth: 5
    • subsample: 0.8
  • Features: All columns except AQI, timestamp, and location
  • Target: AQI values

πŸš€ Deployment

Render/Heroku

  1. Push code to your repository
  2. Connect to Render/Heroku
  3. Use the run.sh script as your start command
  4. Set environment variables if needed

Docker

docker build -t zephra-ml .
docker run -p 8080:8080 zephra-ml

πŸ“Š Model Performance

The model's performance is evaluated using RMSE (Root Mean Square Error) on the test set. Training metrics are displayed during model training.

πŸ”§ Configuration

πŸ“ Notes

  • The model assumes the last feature in the dataset is the lag AQI value for recursive forecasting
  • Adjust the column names in data_loader.py and training scripts based on your actual API response structure
  • The forecast uses recursive prediction where each prediction becomes input for the next step

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published