Machine Learning Based Structural Characterization of Rainfall Event Typology and Regime Shifts in Pakistan (1981–2024)
This repository contains the complete implementation for an event-based machine learning framework that analyzes the structural morphology of rainfall events in Pakistan over a 44-year period.
Traditional rainfall studies rely on accumulated totals, which hide how rainfall actually unfolds in time. Two regions may receive identical rainfall totals but differ significantly in onset speed, peak intensity, and recession behavior. These structural properties determine flooding risk, crop stress, and groundwater recharge.
This project extracts rainfall events from dekadal precipitation records, constructs morphological features describing event shape, discovers natural rainfall typologies through clustering, detects long-term regime shifts, and evaluates machine learning models for typology classification.
The full research work is implemented here along with visualization and model evaluation.
The pipeline processes 44 years of rainfall data (1981–2024) covering 30 districts of Pakistan and performs:
- Rainfall event segmentation
- Morphological feature engineering
- Rainfall typology discovery using clustering
- Regime shift detection in long-term rainfall patterns
- Machine learning classification of rainfall typologies
Key statistics:
- 47,070 dekadal rainfall records
- 30 districts
- 4,563 extracted rainfall events
- 7 rainfall typology classes discovered
Dataset source:
WFP Rainfall Indicators Dataset (Pakistan)
The dataset contains 10-day rainfall observations for multiple districts.
Main variables include:
| Feature | Description |
|---|---|
| date | Dekadal timestamp |
| adm2_id | District identifier |
| ADM2_PCODE | District administrative code |
| rfh | Rainfall total for dekad (mm) |
| rfh_avg | Long-term rainfall average |
| r1h | 1-month rolling rainfall |
| r3h | 3-month rolling rainfall |
| rfq | Dekadal rainfall quantile |
| r1q | 1-month rainfall quantile |
| r3q | 3-month rainfall quantile |
Total records: 47,070
Dekadal rainfall records are converted into discrete rainfall events.
A rainfall event is defined as:
- Consecutive dekads with rainfall greater than 5 mm
- Event ends when rainfall falls below this threshold
Result: 47070 records → 4563 rainfall events
Each rainfall event is represented using 8 structural features describing its temporal shape.
Features include:
| Feature | Description |
|---|---|
| Event Volume | Total rainfall accumulated during event |
| Mean Intensity | Average rainfall per dekad |
| Max Intensity | Maximum rainfall in a dekad |
| Duration | Number of dekads in event |
| Peak Anomaly | Difference from historical mean |
| Rise Gradient | Speed of rainfall increase |
| Decay Gradient | Speed of rainfall decrease |
| RCVR | Rainfall Consonant-Vowel Ratio (wet/dry ratio before event) |
These features encode temporal rainfall structure, not just magnitude.
Rainfall events are clustered into structural types using:
Gaussian Mixture Models (GMM)
Reasons for choosing GMM:
- Allows soft cluster membership
- Handles different cluster variances
- Better suited for overlapping rainfall structures than k-means
Optimal number of clusters determined using:
- Bayesian Information Criterion (BIC)
- Silhouette score
Result: Optimal clusters = 7 rainfall typology classes
To detect long-term structural changes in rainfall patterns, the pipeline applies:
PELT (Pruned Exact Linear Time) changepoint detection
Input:
Annual proportions of rainfall typology classes per district.
Outcome:
A persistent regime shift around 1996 in rainfall event composition across several districts.
This indicates that rainfall structure changed even when total rainfall did not necessarily change.
The project evaluates whether rainfall typologies can be predicted from morphological features.
Models tested:
- Logistic Regression
- Random Forest
- XGBoost
- Artificial Neural Network (ANN)
Train/Test Split: 80% training 20% testing
Hyperparameter tuning: 5-fold cross validation
| Model | Accuracy | Macro F1 |
|---|---|---|
| Logistic Regression | 0.80 | 0.76 |
| ANN | 0.954 | 0.91 |
| XGBoost | 0.963 | 0.93 |
| Random Forest | 0.966 | 0.94 |
Best model:
Random Forest
Important insight:
High overall accuracy hides minority class difficulty.
Rare typologies have lower recall due to class imbalance.
Top features identified by Random Forest:
- RCVR
- Duration
- Event Volume
- Rise Gradient
- Decay Gradient
This shows rainfall typology is driven more by temporal structure than raw intensity.
Interactive rainfall analysis dashboard:
https://pakistan-rainfall-analysis.streamlit.app/
The dashboard allows:
- Typology distribution visualization
- Temporal rainfall pattern exploration
- Model prediction insights
- Rainfall events in Pakistan can be categorized into 7 structural typologies.
- Event morphology provides more insight than simple rainfall totals.
- A major structural rainfall shift occurred around 1996.
- Machine learning models can classify rainfall event types with 96% accuracy.
- Temporal features such as duration and antecedent moisture are more informative than intensity.
- Dekadal resolution hides sub-10-day rainfall bursts.
- Analysis performed at district level.
- Some rainfall types are underrepresented.
- Event gradients assume linear intensity progression.
Future improvements include:
- Using daily rainfall data
- Adding atmospheric variables
- Addressing class imbalance with SMOTE
- Improving minority typology prediction
- Integrating seasonal forecast models
Abdullah Haroon
Computer Science Student
FAST-NUCES Lahore
This project is released for research and academic use.