Abuja, the capital city of Nigeria, is renowned for its modern architecture, political significance, and serene landscapes. However, like many rapidly growing urban centers, Abuja faces environmental challenges, including recurrent flooding during the rainy season. Floods in Abuja have significant socio-economic impacts, affecting infrastructure, livelihoods, and public safety. Predicting floods and understanding rainfall patterns can help mitigate risks, enhance urban planning, and safeguard lives and properties.
This project leverages historical rainfall data to build a predictive model that forecasts flooding in Abuja based on monthly and annual rainfall. By analyzing trends and creating accurate predictions, we aim to contribute to better flood preparedness and management strategies for the city.
The primary goal of this project is to develop a machine learning model that predicts the occurrence of floods in Abuja using historical rainfall data. This includes identifying patterns in rainfall and determining the accuracy of various predictive models.
The dataset contains historical records with the following columns:
CITY: The city where the data was recorded (removed in preprocessing).
YEAR: The year of the data.
JAN - DEC: Monthly rainfall data (in millimeters).
ANNUAL RAINFALL: Total rainfall for the year.
FLOODS: Indicates whether flooding occurred (YES/NO).
Removed the CITY column as it was irrelevant for prediction.
Handled missing values and ensured data consistency.
Converted the FLOODS column into binary values: 1 for "Yes" and 0 for "No".
import pandas as pd
# Load the dataset
data = pd.read_csv('/content/sample_data/ABUJA_FLOODS.csv')
# Drop the CITY column
data = data.drop(['CITY'], axis=1)
# Check for missing values
print(data.isnull().sum())
# Convert the FLOODS column to binary
data['FLOODS'] = data['FLOODS'].replace({'YES': 1, 'NO': 0})
Two machine learning models were trained to predict floods based on rainfall data:
K-Nearest Neighbors (KNN)
Random Forest Classifier
The dataset was split into training and testing subsets (80% training, 20% testing).
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
# Separate features and target
x = data.drop('FLOODS', axis=1)
y = data['FLOODS']
# Split the data
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
# KNN Model
knn_model = KNeighborsClassifier()
knn_model.fit(x_train, y_train)
# Random Forest Model
rf_model = RandomForestClassifier()
rf_model.fit(x_train, y_train)
The models were evaluated using the test dataset. Metrics included:
Accuracy: Measures overall correctness.
Confusion Matrices: Provides insight into true/false positives and negatives.
from sklearn.metrics import accuracy_score, confusion_matrix
# Evaluate KNN Model
knn_predictions = knn_model.predict(x_test)
knn_accuracy = accuracy_score(y_test, knn_predictions)
knn_confusion = confusion_matrix(y_test, knn_predictions)
print("KNN Accuracy:", knn_accuracy)
print("KNN Confusion Matrix:\n", knn_confusion)
# Evaluate Random Forest Model
rf_predictions = rf_model.predict(x_test)
rf_accuracy = accuracy_score(y_test, rf_predictions)
rf_confusion = confusion_matrix(y_test, rf_predictions)
print("Random Forest Accuracy:", rf_accuracy)
print("Random Forest Confusion Matrix:\n", rf_confusion)
K-Nearest Neighbors (KNN) achieved an accuracy score of 1.0.
Random Forest Classifier also achieved an accuracy score of 1.0.
Both models perfectly classified all instances in the test dataset, resulting in no false positives or false negatives.
Annual rainfall trends were the strongest predictor of flood occurrence.
The data preprocessing ensured consistency and improved the models' performance.
Cleaned data with binary encoding for the FLOODS column.
Removed the irrelevant CITY column.
This project demonstrates how machine learning can effectively predict flood occurrences in Abuja using historical rainfall data. By preprocessing the dataset and training predictive models, we achieved perfect accuracy with both the K-Nearest Neighbors (KNN) and Random Forest Classifier models.
The analysis highlights the importance of rainfall data in flood prediction and underscores the value of data preprocessing in enhancing model performance. The results suggest these models can be a reliable tool for early warning systems, enabling better disaster preparedness and resource allocation.
Expanding the dataset to include other predictors such as land use, soil type, and drainage systems could improve model robustness.
Integrate the models into a real-time predictive system for Abuja to provide actionable insights for flood management.
Testing the models with data from other regions could validate their generalizability and improve their applicability on a national or global scale.
Government and relevant authorities should deploy these predictive models as part of a flood early warning system. With real-time rainfall monitoring and prediction, timely evacuation and resource allocation can save lives and mitigate damages.
Invest in consistent and reliable data collection infrastructure, including rainfall measurement stations and flood occurrence reporting systems. Accurate and granular data improves model accuracy and reliability.
Educate the public on flood risks and preparedness strategies, emphasizing the role of rainfall in flood occurrences. Awareness can improve community responses to early warnings.
Encourage partnerships between government agencies, academic institutions, and private organizations to enhance predictive modeling efforts and explore new variables for flood risk analysis.
Use these predictive insights to guide urban planning and infrastructure development, ensuring flood-prone areas are adequately safeguarded with drainage systems and other protective measures.
The dataset used in this project was sourced from the National Bureau of Statistics (NBS). It provides annual rainfall data across different months for Abuja, Nigeria, along with flood occurrence records. The credibility and accuracy of the NBS make it a reliable source for flood prediction analysis.