Interactive Research Paper

GridGenius

Hybrid Machine Learning and Transformer-Based Explainable Energy Demand Forecasting for Bangladesh

Adib Ar Rahman KhanNorth South University
Md Aurongojeb LishadNorth South University
Pranoy SahaNorth South University
Sadia Islam MouNorth South University
Download PDF
Click Figures Hover TermsLike this one! Definitions appear on hover or focus. Expand Sections Best on Desktop

Abstract

Bangladesh faces critical challenges in balancing electricity generation with demand, leading to resource wastage, high costs, and load shedding. We present GridGenius, a novel, fully deployed AIArtificial Intelligence-powered platform for accurate and explainable daily electricity demand forecasting.

The system uses a hybrid model integrating classical MLMachine Learning (Random Forest, XGBoost) with a custom Transformer regressor, achieving Coefficient of Determination: How well predictions replicate real data points (0-1 scale). scores up to 0.89. A unique dataset from 1,800+ daily BPDBBangladesh Power Development Board reports (2020-2024) was created, enriched with holiday, temperature, and seasonal data.

GridGenius incorporates a RAGRetrieval-Augmented Generation: Enhances LLM answers with external knowledge. pipeline with a LLMLarge Language Model (e.g., Llama 3) for transparency, allowing natural language queries about forecasts. Deployed as a web app, it offers a scalable, transparent solution for smarter grid management.


Introduction

Bangladesh's energy sector is marked by a persistent struggle to align electricity generation with national demand. This imbalance results in frequent load shedding, inefficient resource use, and significant economic consequences. Despite generation capacity growth, the BPDBBangladesh Power Development Board [1] still grapples with demand-supply mismatches, especially during peak periods and seasonal transitions. A key bottleneck is the lack of dynamic, interpretable, and real-time forecasting systems [3] to guide grid optimization efforts.

Traditional forecasting approaches, including statistical models (ARIMAAutoregressive Integrated Moving Average) and basic MLMachine Learning techniques, often fall short. They may struggle to generalize across time scales, ignore crucial external factors like holidays or weather patterns, and lack the scalability needed for daily operational deployment. This highlights the need for an intelligent, adaptable system providing accurate daily forecasts coupled with clear, understandable explanations.

Our Contribution: GridGenius

GridGenius is designed to fill this gap by integrating novel, state-of-the-art AI techniques:

  • A Hybrid Modeling Strategy: Combines established ML algorithms (Random Forest, XGBoost) with a custom Transformer architecture [2].
  • Novel & Enriched Dataset: A comprehensive daily record (2020-2024) from BPDB reports [1], enhanced with temperature, holidays, and engineered features.
  • Explainable AI (XAIExplainable Artificial Intelligence) Core [3]: Utilizes a RAGRetrieval-Augmented Generation [4] pipeline with Llama 3.1 [14] for transparent, natural language interaction.
  • Full Deployment: An novel interactive web application providing forecasts, visualizations, and conversational insights.
0
BPDB Reports Processed
Peak R² Score Achieved
4
Years of Data Analyzed


Methodology

GridGenius follows a systematic pipeline:

  1. Data Collection & Preprocessing
  2. Exploratory Data Analysis (EDA)
  3. Feature Engineering
  4. Model Development & Training (Hybrid Approach)
  5. Explainability (RAG-LLM Integration)
  6. System Deployment
Figure 1: GridGenius System Architecture Overview.
Figure 1: GridGenius System Architecture Overview. (Click to Enlarge)

A. Dataset Collection & Description

Unique dataset scraped from 1,800+ daily BPDBBangladesh Power Development Board reports (Jan 2020 - Mid 2024). Includes Max Demand (MW), Max Generation (MW), Date, enriched with Daily Avg Temp (°C) & National Holiday flag.

B. Exploratory Data Analysis (EDA)

EDAExploratory Data Analysis revealed key patterns:

Figure 2: Temperature Distribution histogram showing a peak frequency around 30°C
Fig 2: Temp. Peak ~30°C
Figure 3: Demand Distribution histogram showing a broad spread, slightly skewed right
Fig 3: Broad Demand Spread
Figure 6: Scatter plot showing Demand (Y-axis) generally increasing with Temperature (X-axis), especially above 25°C
Fig 6: Demand Rises with Temp
Figure 7: Box plot comparing Demand on Holidays vs Non-Holidays, showing significantly lower median and range on holidays
Fig 7: Lower Demand on Holidays

C. Feature Engineering & Data Iterations

Features engineered: Demand-Gen Gap, Season Classification, Holiday Flag. Preprocessing: Outlier handling (IQRInterquartile Range, Z-score), Scaling (MinMaxScaler, StandardScaler). Four dataset variants created for robustness testing.

D. Modeling Pipeline

Models explored: Linear Regression, Random Forest (Top Classical), XGBoost, SVR, Transformer (Custom DL). Tuned RF/XGBoost via RandomizedSearchCV.

E. Primary Model: Transformer Regressor

Custom Transformer [2] with multi-head self-attention, feed-forward layers, positional encoding, dropout. Trained with Adam [12] optimizer & MSEMean Squared Error loss.

Table II: Transformer Implementation Details (Selected)
ParameterValue
OptimizerAdam [12]
Loss FunctionMSE
Training Epochs50
Key Hyperparameters Tunednum_heads, model_dim, num_layers, dropout, learning_rate

F. Explainability via RAG-LLM

Achieved using RAGRetrieval-Augmented Generation [4]: ChromaDBVector Database [13] stores context (docs, stats) embedded via Google/HF models [26, 27]. Llama 3.1 [14] on GroqFast LLM Inference API [15] generates answers based on retrieved context, enabling natural language queries.

G. Deployment Architecture

Modern stack: FastAPIPython Backend Framework [16] backend on RailwayCloud Platform [28], Responsive frontend on VercelCloud Platform [17], persistent ChromaDBVector Database [13], GroqFast LLM Inference API [15] for LLMLarge Language Model.

Figure 10: Screenshot of the GridOracle Prediction Tool interface showing input fields (date, temp, holiday) and predicted demand output
Fig 10: GridOracle Tool
Figure 11: Screenshot of the Visualization Dashboard showing time series charts of demand, generation, and temperature
Fig 11: Insights Dashboard
Figure 12: Screenshot of the GridGenius Chatbot interface showing a user query and an LLM-generated explanation
Fig 12: GridGenius Chatbot

Results and Experiments

A. Experimental Setup & Tools

Hybrid setup (Colab T4 GPUGraphics Processing Unit, RTX 3060, M1 Mac). Libs: Sklearn [18], TF [19]/Keras [21], PyTorch [20], NumPy [22], Pandas [23], Matplotlib [24]/Seaborn [25], FastAPIPython Backend Framework [16], ChromaVector Database [13], etc.

B. Evaluation Metrics

Measured by Coefficient of Determination, MAEMean Absolute Error, MSEMean Squared Error, RMSERoot Mean Squared Error.

C. Overall Model Performance

Random Forest & XGBoost excelled among classical models (R² ≈ 0.90).

Table III: Detailed Evaluation (Best Model Per Variant)
Dataset VariantBest ModelMAERMSE
GGDataset_a (MinMax + IQR)Random Forest0.8980.0460.065
GGDataset_b (MinMax + Z-Score)Random Forest0.8920.0480.067
GGDataset_c (StdScaler + IQR)Random Forest0.8980.2260.313
GGDataset_d (StdScaler + Z-Score)Random Forest0.8940.2270.318
Figure 13: Plot showing Random Forest predicted demand (Y-axis) vs actual demand (X-axis), points cluster closely around the diagonal line indicating good fit
Fig 13: Random Forest Perf.
Figure 14: Plot showing XGBoost predicted demand (Y-axis) vs actual demand (X-axis), similar good fit to Random Forest
Fig 14: XGBoost Perf.

D. Hyperparameter Tuning

RandomizedSearchCV significantly boosted RF/XGBoost performance.

E. Transformer Model Results

Strong generalization (R² ≈ 0.82).

R² Score
≈ 0.82
MAE
≈ 0.06*
RMSE
≈ 0.08*
Figure 15: Plot showing Transformer predicted demand (Y-axis) vs actual demand (X-axis), points show good correlation but slightly more scatter than RF/XGBoost
Fig 15: Transformer Perf.
Figure 16: Plot showing Transformer training and validation loss curves decreasing over epochs, indicating learning
Fig 16: Transformer Loss

*MAE/RMSE likely reported on scaled data.

F. Ablation Study: Scaling

MinMaxScaler slightly better for classical models; Transformer less sensitive. Z-score impact minimal vs IQRInterquartile Range for outlier handling.

G. XAI Chatbot Results

RAGRetrieval-Augmented Generation chatbot effectively answered complex queries in real-time (<1s latency via GroqFast LLM Inference API), enhancing transparency.


Conclusion and Future Work

GridGenius presents a significant advancement in energy demand forecasting for Bangladesh. By integrating a novel dataset, hybrid modeling, and an interactive RAGRetrieval-Augmented Generation-based XAIExplainable Artificial Intelligence system, it addresses key limitations. The platform achieves high accuracy (R² ≈ 0.89) and offers unprecedented transparency.

The deployed system provides a practical, scalable tool for grid planners, offering a blueprint for intelligent energy management in developing economies.

  • Data Expansion: Seek pre-2020 BPDB data.
  • Model Refinement: Optimize Transformer (tuning, TCNs [30], Informer [31], multivariate attention [32]).
  • LLMLarge Language Model Enhancement: Improve RAG (prompts, retrieval, LoRALow-Rank Adaptation [29]).
  • Feature Integration: Add economic/operational data.
  • Platform Evolution: Mobile-first UI, public APIsApplication Programming Interface.

References

  1. Bangladesh Power Development Board, "Bangladesh Power Development Board," [Online]. Available: https://www.bpdb.gov.bd/.
  2. A. Vaswani, et al., "Attention Is All You Need," arXiv:1706.03762, 2017. [Online]. Available: https://arxiv.org/abs/1706.03762.
  3. G. P. Reddy and Y. V. P. Kumar, "Explainable AI (XAI): Explained," 2023 IEEE eStream, pp. 1-6, doi: 10.1109/eStream59056.2023.10134984.
  4. P. Lewis, et al., "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks," arXiv:2005.11401, 2020. [Online]. Available: https://arxiv.org/abs/2005.11401.
  5. M. Hossain, et al., "Short-Term Electricity Demand Forecasting of Dhaka City Using Machine Learning Approaches," arXiv:2406.06651, 2024.
  6. Y. Wang, et al., "Short-term power load forecasting using SSA-CNN-LSTM method," Syst. Sci. Control Eng., vol. 12, no. 1, pp. 1-12, 2024. doi: 10.1080/21642583.2024.2343297.
  7. H. Haque and M. A. Razzak, "Medium-Term Energy Demand Analysis Using Machine Learning," SSRN Electron. J., Aug. 2022. doi: 10.2139/ssrn.4197655.
  8. H. Haque, et al., "Long-term Energy Demand Analysis using Machine Learning Algorithms," 2024 6th Int. Conf. SGRE, pp. 1-6. doi: 10.1109/SGRE60102.2024.10815643.
  9. Q. Wen, et al., "Transformers in Time Series: A Survey," arXiv:2202.07125, 2022. [Online]. Available: https://arxiv.org/abs/2202.07125.
  10. H. Wu, et al., "Autoformer: Decomposition Transformers with Auto-Correlation for Long-Term Series Forecasting," arXiv:2106.13008, 2021. [Online]. Available: https://arxiv.org/abs/2106.13008.
  11. IBM, "Using the watsonx.ai Time Series Forecasting API to predict energy demand," IBM Developer, 2025. [Online]. Available: Link.
  12. D. P. Kingma and J. Ba, "Adam: A Method for Stochastic Optimization," arXiv:1412.6980, 2014. [Online]. Available: https://arxiv.org/abs/1412.6980.
  13. Chroma, "Chroma: The AI-native open-source embedding database," GitHub, 2023. [Online]. Available: https://github.com/chroma-core/chroma.
  14. Meta AI, "Introducing Llama 3.1," Meta AI Blog, 2024. [Online]. Available: https://ai.meta.com/blog/meta-llama-3-1/.
  15. Groq, "GroqCloud: Fast AI Inference," 2024. [Online]. Available: https://groq.com/.
  16. S. Ramírez, "FastAPI," 2023. [Online]. Available: https://fastapi.tiangolo.com/.
  17. Vercel, "Vercel Documentation," 2024. [Online]. Available: https://vercel.com/docs.
  18. F. Pedregosa, et al., "Scikit-learn: Machine Learning in Python," JMLR, vol. 12, pp. 2825-2830, 2011.
  19. M. Abadi, et al., "TensorFlow: Large-scale machine learning on heterogeneous systems," arXiv:1603.04467, 2016. [Online]. Available: https://arxiv.org/abs/1603.04467.
  20. A. Paszke, et al., "PyTorch: An Imperative Style, High-Performance Deep Learning Library," NeurIPS, 2019.
  21. F. Chollet, "Keras," GitHub, 2015. [Online]. Available: https://github.com/keras-team/keras.
  22. C. R. Harris, et al., "Array programming with NumPy," Nature, vol. 585, pp. 357-362, 2020.
  23. W. McKinney, "Data Structures for Statistical Computing in Python," Proc. 9th Python Sci. Conf., 2010, pp. 51-56.
  24. J. D. Hunter, "Matplotlib: A 2D Graphics Environment," Comput. Sci. Eng., vol. 9, no. 3, pp. 90-95, 2007.
  25. M. Waskom, "Seaborn: Statistical Data Visualization," J. Open Source Softw., vol. 6, no. 60, p. 3021, 2021.
  26. Google, "Google Cloud AI Platform," 2024. [Online]. Available: https://cloud.google.com/ai-platform.
  27. Hugging Face, "Hugging Face Transformers," 2024. [Online]. Available: https://huggingface.co/transformers/.
  28. Railway, "Railway: Infrastructure for Developers," 2024. [Online]. Available: https://railway.app/.
  29. E. Hu, et al., "LoRA: Low-Rank Adaptation of Large Language Models," arXiv:2106.09685, 2021. [Online]. Available: https://arxiv.org/abs/2106.09685.
  30. S. Bai, et al., "An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling," arXiv:1803.01271, 2018. [Online]. Available: https://arxiv.org/abs/1803.01271.
  31. H. Zhou, et al., "Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting," AAAI, 2021. [Online]. Available: https://arxiv.org/abs/2012.07436.
  32. H. Wu, "Revisiting Attention for Multivariate Time Series Forecasting," arXiv:2407.13806, 2024. [Online]. Available: https://arxiv.org/abs/2407.13806.