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:
- 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.
- 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.

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:
- Accuracy: Indicates the overall proportion of correct predictions. We set realistic benchmarks by comparing against dummy estimators, which make random predictions, to establish a minimum quality threshold.
- Precision, Recall, and F1 Score: The F1 score helps balance precision and recall, providing a comprehensive view of model performance, especially important in the context of our oversampled dataset.
- ROC-AUC: This metric measures the model’s ability to distinguish between rain and no-rain cases across various thresholds. A higher ROC-AUC indicates better performance.
Results
Logistic Regression
- Accuracy: 0.864
- ROC-AUC: 0.864
- Precision:
- Class 0 (No Rain): 0.87
- Class 1 (Rain): 0.86
- Recall:
- Class 0: 0.86
- Class 1: 0.87
- F1 Score:
- Class 0: 0.87
- Class 1: 0.86
-
Performance: Logistic Regression showed balanced performance, with relatively high precision and recall for both “Rain” and “No Rain” predictions. This model serves as a solid baseline, showing that our preprocessing steps and feature selection were effective in generating reasonable predictions.
-
Logistic Regression ROC Curve

- Logistic Regression Confusion Matrix

Random Forest Classifier
- Accuracy: 0.999
- ROC-AUC: 0.999
- Precision, Recall, and F1 Score: All metrics for both classes are 1.00, indicating perfect classification.
-
Performance: Random Forest achieved near-perfect accuracy, which likely reflects the model’s robust ability to generalize across different weather patterns due to its ensemble nature. The high performance across all metrics suggests it successfully captured complex patterns in the data.
-
Random Forest ROC Curve

- Random Forest Confusion Matrix

XGBoost
- Accuracy: 0.985
- ROC-AUC: 0.987
- Precision, Recall, and F1 Score: The XGBoost model demonstrated high precision, recall, and F1 scores across both classes, indicating that it effectively handled the balanced dataset and performed well in both “Rain” and “No Rain” predictions.
-
Performance: XGBoost achieved excellent performance, with high accuracy and ROC-AUC scores. The model’s ability to generalize across different weather patterns stems from its gradient boosting framework, which captures complex nonlinear relationships in the data. The strong results suggest that the preprocessing steps, including oversampling, normalization, and feature selection, were effective in creating a high-performing predictive model.
-
XGBoost ROC Curve

- XGBoost Confusion Matrix

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:
- 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.
- Strengths:
- 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.
- Strengths:
- 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.
- Strengths:
Tradeoffs and Insights
- Logistic Regression is ideal for quick baseline modeling but falls short in handling the nonlinear complexities of weather data.
- Random Forest excels in accuracy and interpretability through feature importance scores but can be computationally heavy for larger datasets.
- XGBoost strikes a good balance between performance and computational efficiency, making it the most versatile model for this dataset.
Visualizations for Comparison
Accuracy Comparison

ROC-AUC Comparison

Next Steps
- Hyperparameter Tuning: Further fine-tune the hyperparameters of Random Forest and XGBoost to explore potential performance improvements.
- Cross-Validation: Implement k-fold cross-validation for all models to verify generalizability across multiple data splits.
- Feature Engineering: Investigate additional features or transformations that may improve predictive power.
- Scalability: Explore distributed implementations for Random Forest and XGBoost to handle larger datasets efficiently.
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