Skip to content

Repository files navigation

ENSEMBLE LEARNING FOR ROAD FLOOD PREDICTION

This project trains and evaluates multiple machine learning models for road network flood prediction, generates performance metrics, visualizes model performance with heatmaps, and provides SHAP explanations machine learning model. The code is modularized into separate Python files for training individual models, ensemble models (voting and stacking), plotting heatmaps, and explaining the AdaBoost model with SHAP.

Project Structure

The project consists of six Python files and expects a dataset (flood.csv) as input. The code automatically creates necessary directories for input and output files.

Files

  • main.py: Orchestrates data loading, model training, evaluation, and visualization. It reads the input dataset, calls training functions, saves results, and generates visualizations.
  • train_individual_models.py: Trains and evaluates individual machine learning models (Random Forest, CatBoost, AdaBoost, SVM, Bagging, Gradient Boosting).
  • train_voting_model.py: Trains and evaluates a VotingClassifier using selected individual models.
  • train_stacking_model.py: Trains and evaluates a StackingClassifier using selected individual models.
  • plot_heatmaps.py: Generates two heatmaps: one for model performance rankings and another for relative improvement compared to Random Forest.
  • explain_adaboost.py: Computes SHAP values for the AdaBoost model and generates a violin summary plot.

Directory Structure

  • Database/: Stores the input dataset (flood.csv). Created automatically if it doesn't exist.
  • Results/Tables/: Stores the output CSV file with model performance metrics (model_perform_new.csv).
  • Results/Figure/: Stores visualization outputs (model_performance_heatmaps.png and adaboost_shap_summary.png).

Prerequisites

Dependencies

Install the required Python libraries using pip:

pip install numpy pandas matplotlib seaborn catboost scikit-learn shap

Dataset

  • The project expects a dataset named flood.csv in the Database/ folder.
  • The dataset should have:
    • A target column (first column) for flood prediction (binary classification).
    • Seven feature columns (columns 1-9) named: ELEVATION, STREAM, RAINFALL, STORMWATER, SLOPE, ROUGHNESS, CN.
  • Ensure the dataset is clean (no missing values) or the code will automatically drop rows with missing values.

Setup

  1. Clone or Download the Project:

    • Save all six Python files (main.py, train_individual_models.py, train_voting_model.py, train_stacking_model.py, plot_heatmaps.py, explain_adaboost.py) in a single directory.
  2. Place the Dataset:

    • Place flood.csv in the Database/ folder. If the folder doesn't exist, it will be created when you run the script.
  3. Install Dependencies:

    • Run the pip command above to install required libraries.

Running the Project

  1. Navigate to the Project Directory:

    cd /path/to/project
  2. Run the Main Script:

    python main.py
  3. Expected Output:

    • Console Output:
      • Displays a DataFrame with performance metrics (Accuracy, Kappa score, Precision, Recall, F1-score, ROC AUC) for all models.
      • Confirms the SHAP summary plot has been saved.
    • Files Generated:
      • Results/Tables/model_perform_new.csv: CSV file with model performance metrics.
      • Results/Figure/model_performance_heatmaps.png: Heatmaps showing model rankings and relative improvement compared to Random Forest.
      • Results/Figure/adaboost_shap_summary.png: SHAP violin summary plot for the AdaBoost model.

Notes

  • Directory Creation: The script automatically creates Database/, Results/Tables/, and Results/Figure/ if they don't exist.
  • Dataset Requirements: Ensure flood.csv is in the Database/ folder and matches the expected format. If the file is missing, a FileNotFoundError will be raised.
  • SHAP Performance: Computing SHAP values for large datasets can be slow. Consider sampling the dataset (e.g., uncomment shap.sample(X, 300, random_state=42) in explain_adaboost.py) for faster computation.
  • Visualization: Plots are saved as PNG files but not displayed. To display plots, add plt.show() before plt.close() in plot_heatmaps.py and explain_adaboost.py.

Troubleshooting

  • Missing Dataset: If flood.csv is not found, ensure it is placed in the Database/ folder.
  • Library Errors: Verify all dependencies are installed correctly.
  • Large Datasets: If SHAP computation is slow, reduce the dataset size by sampling in explain_adaboost.py.

License

This project is provided as-is for educational purposes. Ensure you have the necessary permissions to use the dataset (flood.csv).

👨‍🔬 Authors

Developed by Yogesh Bhattarai(yogeshbhattarai.sb@gmail.com)

About

This project trains and evaluates multiple machine learning models for road network flood prediction in the urban cities.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages