Skip to content

tenzodin/fire-predict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

80 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”ฅ Forest Fire Predictor

An AI-powered web app that predicts and visualizes wildfire risk across Ontario based on user-uploaded weather data.


๐ŸŒ What It Does

  1. Upload a .csv file containing weather data for Ontario stations.
  2. A machine learning model predicts wildfire occurrence tiers (Low / Moderate / High / Extreme) for the next month.
  3. Results are visualized on an interactive Leaflet map with color-coded markers and a visible legend:
    • ๐ŸŸข Low Risk โ€” Fewer than 50 fires โ€” Routine local response
    • ๐ŸŸก Moderate โ€” 50โ€“150 fires โ€” Regional resource prep
    • ๐ŸŸ  High โ€” 150โ€“300 fires โ€” Full deployment
    • ๐Ÿ”ด Extreme โ€” Over 300 fires โ€” National/international coordination
  4. Each marker includes a GPT-generated explanation and prevention tip.

๐Ÿš€ Tech Stack

Tool/Library Usage
๐Ÿง  scikit-learn ML model (Random Forest Regressor)
โš™๏ธ FastAPI (Python) Backend API
๐ŸŒ React + Tailwind Frontend web app
๐Ÿ—บ๏ธ React-Leaflet Interactive maps
๐Ÿค– OpenAI GPT Natural language fire risk summaries
โ˜๏ธ Vercel + Render Frontend and backend hosting

๐Ÿง  How It Works

 ```mermaid graph TD A[User Uploads CSV] --> B[FastAPI Backend] B --> C[ML Model (.pkl)] C --> D[Predicted Fire Count] D --> E[Frontend Receives Prediction] E --> F[Animated Number Display] E --> G[Map Color Update] G --> H[CircleMarker Color & Tooltip] ``` 

๐Ÿ“ Project Structure

forest-fire-predictor/
โ”œโ”€โ”€ ml-model/              
โ”‚   โ”œโ”€โ”€ train_model.py
โ”‚   โ”œโ”€โ”€ merge_weather_fire.py
โ”‚   โ”œโ”€โ”€ forest_fire_merged.pkl
โ”‚   โ””โ”€โ”€ fire_counts_clean.csv
โ”œโ”€โ”€ web-app/
โ”‚   โ”œโ”€โ”€ frontend/   # React + Tailwind + Leaflet
โ”‚   โ””โ”€โ”€ backend/    # FastAPI
โ”‚       โ”œโ”€โ”€ main.py
โ”‚       โ”œโ”€โ”€ model_loader.py
โ”‚       โ””โ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md

๐Ÿ“ฆ Getting Started

๐Ÿ”ง Backend (FastAPI)

cd web-app/backend
pip install -r requirements.txt
uvicorn main:app --reload

๐ŸŒ Frontend (React)

cd web-app/frontend
npm install
npm run dev

Set .env in frontend/:

VITE_API_URL=http://localhost:8000

๐Ÿ“ Sample CSV Format

Station,TempMax,TempMin,TempMean,Precipitation,CoolingDegreeDays
Pickle Lake,32,5,18,65,45
Red Lake,30,6,17,70,50
Sioux Lookout,33,4,19,80,60

Each row = 1 Ontario station ๐Ÿ“ˆ Output = wildfire tier + natural language explanation


๐Ÿค– Example GPT Explanation

โ€œThis location is at high risk due to elevated temperatures (34ยฐC), low humidity, and low rainfall. Avoid open flames and clear dry brush near your property.โ€


๐Ÿ—บ๏ธ Interactive Map Features

  • Leaflet map renders all Ontario fire stations

  • CircleMarkers color-coded by predicted fire count:

    • ๐ŸŸข 0โ€“49
    • ๐ŸŸก 50โ€“99
    • ๐ŸŸ  100โ€“149
    • ๐Ÿ”ด 150+
  • Hover tooltip shows station name + predicted fire count

  • Legend explains color scale

  • Smooth color fade transitions using CSS


๐Ÿ“ˆ Fire Prediction Model

Trained with a Random Forest Regressor to predict monthly fire counts from historical weather.

๐Ÿ”ข Features

Feature Description
Tm Mean Temperature (ยฐC)
Tx Max Temperature (ยฐC)
Tn Min Temperature (ยฐC)
S Rainfall (mm)
P Precipitation (mm)
CDD Cooling Degree Days
Month Weather month number
Year Year of record

๐Ÿ” Prediction Output

A fire count (rounded) โ†’ Mapped to Risk Tier:

Risk Tier Fires per Month Response Level
๐ŸŸข Low 0โ€“49 Routine local response
๐ŸŸก Moderate 50โ€“150 Pre-position regional resources
๐ŸŸ  High 150โ€“300 Full deployment
๐Ÿ”ด Extreme Over 300 National/international assistance

๐Ÿงช Sample Model Usage

import pandas as pd
import pickle

# Load model
with open("forest_fire_model_aggregated.pkl", "rb") as f:
    model = pickle.load(f)

# Predict
X_new = pd.DataFrame([{
    "Tm": 17.5,
    "Tx": 32.0,
    "Tn": 3.0,
    "S": 0.0,
    "P": 60.0,
    "CDD": 25.0,
    "Weather_Month_Num": 6,
    "Year": 2024
}])

y_pred = model.predict(X_new)
print("Predicted fires:", y_pred)

โœ… Current Status

โœ”๏ธ Core pipeline complete:

  • โœ… Cleaned weather + fire count datasets (2000โ€“2023)
  • โœ… Merged and aggregated per station per month
  • โœ… Trained ML model on aggregated dataset
  • โœ… Backend integration and prediction API
  • โœ… CSV upload + file parsing working
  • โœ… Map color visualization and tooltips

โณ UX Features

  • Animated splash loader (~1.5s)
  • Prediction button disables on click
  • RingLoader spinner during model run
  • Fire count animates from 0 to predicted value

๐Ÿ”ฎ Future Enhancements

  • ๐Ÿ” Integrate live weather APIs (e.g., OpenWeatherMap)
  • ๐Ÿ›ฐ๏ธ Add satellite/vegetation data
  • ๐Ÿ”„ Monthly model retraining
  • ๐Ÿ“Š Add dashboard for trend analysis

๐Ÿ“ Live Demo


๐Ÿ‘ฅ Team

Member
Madison Zhang
Tenzing Woser
Preethi Kamalakkannan

๐Ÿ“œ License

MIT License

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors