Skip to the content.

1. Introduction/Background

Literature Review

Rainfall prediction is a critical area of study with historical roots stretching back to 650 B.C., when ancient Babylonians attempted to forecast weather patterns. Over the centuries, rainfall forecasting has evolved from simple observational methods to complex scientific models, becoming increasingly important for various sectors, particularly in agriculture and urban planning. Accurate rainfall prediction supports farmers in crop management, helps urban planners mitigate flood risks, and enables communities to better prepare for adverse weather events. Today, machine learning and artificial intelligence are transforming this field, offering promising tools to handle complex, nonlinear patterns in weather data [1].

With the rise of climate change, predicting rainfall has become more challenging and urgent. Extreme weather events, such as the recent Helena storm, underscore the need for precise forecasting models that can adapt to changing weather patterns. Effective rainfall prediction models allow us to manage water resources more efficiently, prepare for natural disasters, and protect both life and property [3].

Dataset Description

The dataset used for this project contains weather data from 20 major cities across the USA. Key features include temperature, humidity, wind speed, precipitation, cloud cover, and atmospheric pressure. These features are essential indicators of rainfall and help model complex patterns in weather conditions across different regions. By analyzing these features, the project aims to develop a predictive model that can forecast whether it will rain the next day (labelled as “Rain Tomorrow”).

Link to Dataset: USA Rainfall Prediction Dataset (2024-2025)

2. Problem Definition

Problem

Rainfall prediction remains an inherently complex task due to the chaotic and dynamic nature of weather patterns. Each region in the dataset has unique weather factors, which add to the difficulty of building a universally accurate model. Given the impact of unpredictable weather events like the Helena storm, reliable forecasting has never been more crucial. This project addresses the problem of accurately predicting rainfall by examining weather data from multiple cities, aiming to produce a model that generalizes well across diverse climates.

Motivation

Accurate rainfall predictions serve two primary purposes:

  1. Water Resource Management: Rain is a fundamental resource for all life forms. By forecasting rainfall accurately, communities can better manage water resources, mitigate drought impacts, and plan for sustainable water use.
  2. Disaster Preparedness: Rainfall can lead to severe consequences, including flooding, property damage, and even loss of life. Enhanced prediction models can help people prepare for rain-induced hazards, minimizing their potential impact.

By improving rainfall prediction, we contribute to a broader effort to protect lives, support agriculture, and foster resilience in the face of climate change.

3. Methods

Data Processing Methods

Oversampling: To address the significant class imbalance in the dataset, where “No Rain” instances far outnumbered “Rain Tomorrow” instances, we applied oversampling. Specifically, we used methods like SMOTE (Synthetic Minority Oversampling Technique) to generate synthetic samples of the minority class, “Rain Tomorrow.” This approach ensures a more balanced dataset, preventing the model from favoring the majority class and improving its ability to predict rainfall accurately. By correcting the imbalance, we reduced bias and enhanced the model’s overall performance.

NewYorkImbalance NewYorkBalance

Normalization: Weather features like temperature and humidity operate on vastly different scales, which can skew model training. To address this, we normalized the dataset using the MinMaxScaler from scikit-learn. This process scaled all feature values to fall within a range of 0 to 1, ensuring each feature contributed equally during model training. Normalization is crucial for algorithms like Logistic Regression and XGBoost, which are sensitive to variations in feature scales, as it helps the model converge faster and perform better.

Handling Missing Values: Missing data is common in weather datasets due to sensor errors or incomplete collection. To ensure the integrity of our analysis, we used SimpleImputer from scikit-learn to fill missing values. For numerical features like temperature and humidity, mean or median imputation was applied, while categorical variables were imputed with their mode. Addressing these gaps allowed us to maintain a complete dataset, reducing the risk of inaccurate predictions and improving model reliability.

Feature Selection: Not all features in the dataset were equally relevant for predicting rainfall. To identify the most predictive features, we conducted correlation analysis and used the SelectKBest algorithm. This technique ranks features based on statistical tests, such as chi-squared or mutual information, and retains only the top-performing ones. Feature selection reduced dimensionality, improving model interpretability and efficiency while reducing the risk of overfitting.

Remove Outlier Outliers, such as extreme temperatures or improbable humidity levels, can distort model predictions. To address this, we applied the Interquartile Range (IQR) method, which identifies and removes data points that fall outside 1.5 times the IQR above the third quartile or below the first quartile. Removing these anomalies ensured that the dataset reflected realistic weather conditions, improving the model’s robustness and accuracy.

Machine Learning Models

Logistic Regression: Logistic Regression is a simple yet effective model for binary classification tasks like rainfall prediction. It predicts the probability of “Rain Tomorrow” using a logistic function, making it ideal for problems where interpretability is important. We enhanced this model by applying L1 and L2 regularization to reduce overfitting and handle noise in the data. Logistic Regression also provided insights into the importance of each feature, making it a reliable baseline for our analysis.

Random Forest: Random Forest is a powerful ensemble method that overcomes the limitations of single decision trees by constructing multiple trees and aggregating their predictions. Each tree is trained on a bootstrapped subset of the data, and random subsets of features are considered at each split. This randomness helps reduce overfitting and ensures robustness. We optimized the model by tuning hyperparameters like the number of trees and their depth, which allowed us to capture the complex, non-linear relationships in weather data effectively.

XGBoost: This model is a powerful gradient boosting algorithm designed for structured data tasks, like predicting “Rain” or “No Rain.” XGBoost builds a lot of decision trees sequentially, where each new tree corrects errors made by previous ones. XGBoost is really fast and it is particularly effective at handling large datasets with complex patterns, making it well-suited for weather prediction tasks while preventing overfitting through regularization techniques.

4. Results and Discussion

Quantitative Metrics

The models were evaluated using the following metrics:

Results

Logistic Regression

Random Forest Classifier

XGBoost

Analysis and Discussion

The oversampling approach used in this study significantly enhanced the detection of minority class instances, such as rainy days, ensuring balanced predictions across all models. Logistic Regression, despite its simplicity, served as a strong baseline by providing interpretable results and demonstrating the effectiveness of the preprocessing steps. On the other hand, Random Forest’s near-perfect accuracy highlights its ability to handle complex patterns in the data but raises valid concerns about potential overfitting or data leakage. Although cross-validation indicated that Random Forest generalized well, additional testing on an external dataset is necessary to confirm its robustness. XGBoost stood out as the most versatile model, balancing computational efficiency and high accuracy, making it an excellent choice for this predictive task.

The unusually high accuracy of 99.9% achieved by Random Forest requires further investigation. This result could stem from several factors. First, the oversampling technique, such as SMOTE, might have inadvertently introduced patterns that the model learned too well, amplifying its performance. Second, Random Forest could be heavily reliant on a subset of highly predictive features, making it less sensitive to less informative ones. Lastly, the dataset’s inherent characteristics, including potential seasonality or highly correlated features, may have simplified the problem, leading to inflated accuracy. To address these concerns, future steps should involve testing the model on an entirely unseen dataset, reducing the influence of highly correlated features, and introducing controlled noise to evaluate the model’s robustness. These steps will help ensure the reliability and generalizability of the model’s predictions.

Comparison of Models

The comparison between Logistic Regression, Random Forest, and XGBoost highlights the strengths and limitations of each model:

  1. Logistic Regression:
    • Strengths:
      • Provides interpretable results, making it a strong baseline model.
      • Computationally efficient, with quick training and prediction times.
      • Performed reasonably well, with an accuracy of 86.4% and an ROC-AUC of 0.864, indicating balanced predictions for both classes.
    • Limitations:
      • Struggles with capturing complex patterns in the data due to its linear nature.
      • Slightly lower performance compared to Random Forest and XGBoost, as it cannot model nonlinear relationships effectively.
  2. Random Forest:
    • Strengths:
      • Achieved near-perfect accuracy (99.9%) and ROC-AUC (99.9%), thanks to its ensemble approach, which combines multiple decision trees for robust performance.
      • Handles both linear and nonlinear relationships effectively, making it well-suited for the complex weather dataset.
      • Resistant to overfitting due to random sampling and feature selection in tree construction.
    • Limitations:
      • Computationally expensive, especially when training on large datasets.
      • High performance might suggest overfitting, though cross-validation and test results indicate good generalization.
  3. XGBoost:
    • Strengths:
      • Offers a competitive balance between speed and accuracy, with an accuracy of 98.5% and an ROC-AUC of 98.7%.
      • Captures complex, nonlinear relationships efficiently through gradient boosting.
      • Built-in regularization helps prevent overfitting, even with a large number of estimators.
    • Limitations:
      • Slightly more computationally expensive compared to Logistic Regression.
      • Requires careful tuning of hyperparameters to achieve optimal performance.

Tradeoffs and Insights


Visualizations for Comparison

Accuracy Comparison

Model Accuracy Comparison

ROC-AUC Comparison

Model ROC-AUC Comparison


Next Steps

5. References

[1] NASA, “Weather Forecasting Through the Ages,” Nasa.gov, Feb. 25, 2002. https://earthobservatory.nasa.gov/features/WxForecasting/wx2.php

[2] R. Jayalakshmi and A. Sangavi, “Weather Forecast Prediction Using Machine Learning,” International Journal of Engineering and Advanced Technology (IJEAT), vol. 8, no. 6, pp. 328-331, 2019.

[3] D. Sharma and V. Soni, “A Study on the Rainfall Prediction Using Machine Learning Algorithms,” International Journal of Innovative Technology and Exploring Engineering (IJITEE), vol. 9, no. 1, pp. 165-168, 2019.

[4] S. Kaur and H. S. Dhillon, “An Efficient Rainfall Prediction Model Using Machine Learning Algorithms,” Journal of Engineering and Applied Sciences, vol. 14, no. 23, pp. 8874-8880, 2019.

[5] P. Chattoraj and S. S. De, “Machine Learning Approach for Rainfall Prediction in India,” Advances in Intelligent Systems and Computing, vol. 1085, pp. 391-398, 2020.

[6] “3.4. metrics and scoring: Quantifying the quality of predictions,” scikit, https://scikit-learn.org/stable/modules/model_evaluation.html.

[7] “Model Selection: Cross-validation and GridSearchCV.” scikit, https://scikit-learn.org/stable/model_selection.html.

[8] IBM, “What is Random Forest?,” IBM, https://www.ibm.com/topics/random-forest

Gantt Chart and Contribution Table