Skip to content

nitinc264/Flood-prediction-Model

Repository files navigation

🌊 RiskRadar β€” Flood Risk Prediction System

An End-to-End Machine Learning System for Flood Risk Prediction using Hydrological, Meteorological, and Geospatial Data.
Built using XGBoost, deployed with FastAPI, and visualized through an interactive Streamlit Dashboard.


Python XGBoost FastAPI Streamlit Accuracy F1 Score


πŸš€ Live Demo

πŸ‘‰ Try RiskRadar Live


πŸ“Œ Table of Contents


πŸ“– Overview

RiskRadar is a production-grade flood risk prediction system that analyzes hydrological, meteorological, and geospatial parameters to classify locations into flood risk categories.

The project leverages a high-performance XGBoost Machine Learning model trained on real-world flood datasets and provides predictions through:

  • πŸš€ FastAPI REST API
  • πŸ“Š Interactive Streamlit Dashboard
  • 🐳 Dockerized Deployment Pipeline

Unlike a traditional ML notebook project, RiskRadar focuses on a complete deployment-ready architecture suitable for real-world usage.


✨ Key Features

βœ… Trained on 45,932 global flood locations
βœ… Achieved 96.9% Accuracy
βœ… F1 Score: 0.984
βœ… Uses SMOTE for class imbalance handling
βœ… Real-time prediction dashboard with Plotly visualizations
βœ… FastAPI backend with input validation
βœ… Interactive flood-risk mapping
βœ… Docker-ready deployment
βœ… Production-oriented ML workflow


🧠 Model & Methodology

πŸ“‚ Dataset

  • Source: IIT Delhi Static Flood Database
  • Dataset File: kuntla_flooddatabase.csv
  • Raw Features: 93
  • Final Engineered Features: 13
  • Target: Flood Risk Classification

πŸ”„ Machine Learning Pipeline

Raw Dataset (93 Parameters)
        ↓
Missing Value Handling
        ↓
Feature Engineering
        ↓
Categorical Encoding
        ↓
Train/Test Split
        ↓
SMOTE Balancing
        ↓
Hyperparameter Tuning
        ↓
XGBoost Training
        ↓
Evaluation & Model Export
        ↓
FastAPI + Streamlit Deployment

βš™οΈ Data Preprocessing

Missing Value Handling

  • Dropped columns with more than 40% missing values
  • Median imputation for numerical features

Feature Engineering

Created custom engineered features such as:

  • precipitation_risk_index
  • drainage_risk_index

Encoding

Applied Label Encoding for:

  • Climate Type
  • Landcover Type
  • Soil Type
  • Lithology Type

πŸ€– Model Training

Algorithm Used

  • XGBoost Classifier

Hyperparameter Optimization

  • RandomizedSearchCV
  • 50 parameter combinations
  • 3-fold cross-validation
  • GPU accelerated training (tree_method=hist)

Handling Imbalanced Data

  • Applied SMOTE on training dataset

πŸ“Š Results

Metric Score
Accuracy 96.9%
F1 Score 0.984
Recall 0.791

🌍 High Risk Locations

  • High-risk locations identified: 2,538
  • Total locations analyzed: 45,932

πŸ”₯ Most Important Risk Factors

  • Annual Precipitation
  • Seasonal Rainfall Patterns
  • Drainage Density
  • Basin Relief
  • Soil Characteristics
  • Land Cover Features
  • Temperature Seasonality

πŸ—οΈ Project Structure

riskradar/
β”‚
β”œβ”€β”€ flood_fast.py
β”œβ”€β”€ api.py
β”œβ”€β”€ app.py
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ flood_model.pkl
β”œβ”€β”€ encoders.pkl
β”œβ”€β”€ feature_columns.pkl
β”œβ”€β”€ high_risk_locations.csv
└── README.md

βš™οΈ Installation

1️⃣ Clone Repository

git clone https://github.com/nitinc264/Flood-prediction-Model.git
cd Flood-prediction-Model

2️⃣ Create Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

Linux / Mac

python3 -m venv venv
source venv/bin/activate

3️⃣ Install Dependencies

pip install -r requirements.txt

πŸš€ Running the Project

▢️ Start FastAPI Backend

uvicorn api:app --reload --port 8000

API Documentation

http://localhost:8000/docs

▢️ Start Streamlit Dashboard

Open a new terminal and run:

streamlit run app.py

Dashboard URL

http://localhost:8501

πŸ”Œ API Reference

Method Endpoint Description
GET / API Information
GET /health Health Check
GET /features Feature List
POST /predict Flood Risk Prediction

πŸ“₯ Sample Prediction Request

curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{
  "annual_precipitation": 1500,
  "precipitation_of_wettest_month": 400,
  "precipitation_seasonality": 60,
  "drainage_density": 3.5,
  "drainage_texture": 12.0,
  "basin_relief": 800,
  "annual_mean_temperature": 22,
  "temperature_seasonality": 600,
  "curve_number_amcii": 75,
  "ruggedness_number": 0.8,
  "infiltration_number": 6,
  "climate_type": 2,
  "landcover_type": 1,
  "soil_type": 3
}'

πŸ“€ Sample Response

{
  "flood_risk_score": 0.8341,
  "risk_percentage": "83.4%",
  "risk_level": "HIGH",
  "color": "red",
  "message": "Immediate attention required. High probability of flood event.",
  "features_used": 13
}

🐳 Docker Support

Build Docker Image

docker build -t riskradar .

Run Docker Container

docker run -p 8000:8000 riskradar

πŸ› οΈ Tech Stack

Layer Technology
Machine Learning XGBoost, Scikit-learn
Data Processing Pandas, NumPy
Imbalanced Learning SMOTE
Backend API FastAPI, Uvicorn
Frontend Dashboard Streamlit
Visualization Plotly, Folium, Matplotlib
Deployment Docker
Training Environment Google Colab

πŸ“ˆ Future Scope

  • Hugging Face deployment βœ“ β€” Live at nitin454545-riskradar.hf.space
  • Real-time weather API integration
  • Global-scale flood dataset expansion
  • SMS & Email flood alerts
  • Mobile-responsive frontend
  • Live geospatial monitoring
  • Cloud deployment pipeline

πŸ“œ License

This project is licensed under the MIT License.

You are free to:

  • Use
  • Modify
  • Distribute
  • Improve

with proper attribution.


πŸ‘¨β€πŸ’» Author

Nitin Chauhan

πŸŽ“ B.Tech β€” AI & Data Science
🏫 Dr. D.Y. Patil School of Science and Technology

Portfolio GitHub LinkedIn


⭐ If you found this project useful, don't forget to star the repository!

About

🌊 RiskRadar: End-to-end Flood Risk Prediction system. Features an XGBoost model (96.9% accuracy) served via FastAPI and visualized through a Streamlit dashboard.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors