YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Machine Learning & Deep Learning Models for Renewable Energy Forecasting
π¨βπ» Author
Momen
This repository contains three machine learning and deep learning implementations for renewable energy prediction and forecasting.
The original approaches were studied and modified, organized, and adapted by Momen to improve the data preprocessing, model training workflow, evaluation, visualization, and overall experimentation process.
π Project Overview
The project focuses on using Machine Learning and Deep Learning techniques to analyze and predict renewable energy generation.
The three notebooks cover different forecasting scenarios:
- Wind Power Prediction using Random Forest
- Solar Irradiance Prediction using Random Forest & XGBoost
- Solar PV Nowcasting using a CNN-based SUNSET Model
The project demonstrates a progression from traditional ensemble machine learning models to deep learning-based image forecasting.
π Models
| Model | Task | Algorithm | Target |
|---|---|---|---|
| Model 1 | Wind Power Prediction | Random Forest Regressor | Power |
| Model 2 | Solar Irradiance Prediction | Random Forest + XGBoost | G(i) |
| Model 3 | Solar PV Nowcasting | CNN + Ensemble Learning | PV Output |
1. π¬οΈ Wind Power Prediction β Random Forest
π― Objective
The first notebook predicts wind power generation using meteorological and temporal features.
The main goal is to learn the relationship between environmental conditions such as:
- Temperature
- Wind speed
- Wind gusts
- Time-related information
and the generated wind power.
The target variable is:
Power
π Dataset
The model uses a wind-energy dataset stored in:
Wind.csv
The dataset contains weather-related measurements and power generation information.
The data includes features such as:
temperature_2m
windspeed_10m
windgusts_10m
City
Date
Time
Power
π§ Data Preprocessing
The notebook performs several preprocessing steps.
Date & Time Processing
The separate Date and Time columns are combined into a single datetime representation.
Temporal features are then extracted:
Year
Month
Day
Hour
DayOfWeek
The original date/time columns are removed after feature extraction.
π Exploratory Data Analysis
The notebook includes several visualizations to understand the dataset:
Power Distribution
A histogram with KDE is used to analyze the distribution of generated power.
Correlation Heatmap
A correlation matrix is generated to investigate relationships between numerical variables.
Feature Relationships
Pair plots are used to visualize the relationship between:
temperature_2m
windspeed_10m
windgusts_10m
Power
π§ Model
The main model is:
RandomForestRegressor
Configuration:
n_estimators = 200
max_depth = 10
random_state = 42
n_jobs = -1
Random Forest was selected because it can model nonlinear relationships between weather conditions and power generation.
βοΈ Feature Scaling
StandardScaler is applied to the input features before training.
The data is split into:
80% Training
20% Testing
π Evaluation Metrics
The model is evaluated using:
RMSE
Root Mean Squared Error measures the average magnitude of prediction errors.
MAE
Mean Absolute Error measures the average absolute difference between actual and predicted values.
RΒ² Score
Measures how well the model explains the variance in the target variable.
π Visualizations
The notebook generates:
Actual vs Predicted Power plot
Random Forest Feature Importance plot
Power distribution
Correlation heatmap
Feature relationship plots
2. βοΈ Solar Irradiance Prediction β Random Forest & XGBoost
π― Objective
The second notebook focuses on predicting solar irradiance using weather, geographic, temporal, and city-level information.
The target variable is:
G(i)
The goal is to estimate solar irradiance using machine learning models and compare the performance of:
Random Forest
XGBoost
π Dataset
The notebook uses a PVGIS-based dataset containing European city solar data.
Example filename:
europe_cities_pvgis_data_slope_45_azimuth_180(in).csv
The dataset includes information related to:
City
Time
Solar irradiance
Weather/environmental measurements
Geographic/solar system characteristics
π Temporal Feature Engineering
The original time information is converted into a datetime representation.
The following features are extracted:
Month
Day
Hour
Minute
To better represent the cyclical nature of time, sinusoidal encoding is applied.
Hour Encoding
Hour_sin
Hour_cos
Month Encoding
Month_sin
Month_cos
This allows the model to understand that:
23:00
and
00:00
are close in time rather than being completely different numerical values.
ποΈ City Encoding
The dataset contains a categorical City feature.
Instead of one-hot encoding potentially large numbers of categories, the notebook uses:
TargetEncoder
from:
category_encoders
This converts city information into numerical representations based on the target variable.
π Preprocessing Pipeline
A Scikit-learn ColumnTransformer is used to create a preprocessing pipeline.
Categorical Features
City β TargetEncoder
Numerical Features
Numerical features β StandardScaler
This preprocessing is integrated directly into the model pipeline.
π² Random Forest Optimization
The Random Forest model is optimized using:
RandomizedSearchCV
The search explores parameters such as:
n_estimators
max_depth
min_samples_split
min_samples_leaf
To reduce computational requirements, a training sample of:
30,000 samples
is used during hyperparameter optimization.
The best estimator is then evaluated against the complete test set.
π XGBoost Optimization
The second model is:
XGBRegressor
Hyperparameter optimization is also performed using:
RandomizedSearchCV
The search explores:
n_estimators
max_depth
learning_rate
subsample
The optimized model is then evaluated on the test dataset.
π Evaluation
Both models are evaluated using:
MAE
RMSE
RΒ²
A performance summary is generated to compare the two approaches.
Example structure:
Model MAE RMSE RΒ²
Random Forest ... ... ...
XGBoost ... ... ...
The actual values depend on the dataset and execution environment.
π Feature Importance
Feature importance is extracted from both:
Random Forest
XGBoost
The notebook visualizes the top features contributing to solar irradiance prediction.
This helps identify which environmental and temporal variables have the strongest influence on the prediction.
π Error Analysis
Prediction errors are calculated as:
True Value - Predicted Value
The error distributions of Random Forest and XGBoost are visualized using histograms and KDE curves.
This provides additional insight into:
Prediction bias
Error distribution
Model stability
Differences between the two algorithms
3. π SUNSET Solar PV Nowcasting β CNN
π― Objective
The third notebook implements a deep learning-based solar photovoltaic (PV) nowcasting model.
Unlike the previous models, which primarily use tabular weather and temporal data, this model works with image-based solar observations.
The goal is to predict near-term PV power output from image sequences and related PV data.
The implementation is based on the SUNSET nowcasting approach, using a Convolutional Neural Network (CNN).
π Dataset
The model works with an HDF5 dataset:
nowcast_dataset.hdf5
The data contains separate training/validation and testing groups.
The main inputs include:
images_log
pv_log
The image data is processed as:
64 Γ 64 Γ 24
where the 24 channels represent the image information available to the model.
The corresponding PV output is used as the regression target.
π§ CNN Architecture
The model is implemented using:
TensorFlow
Keras
The architecture contains:
Input
64 Γ 64 Γ 24
Convolution Block 1
Conv2D
BatchNormalization
MaxPooling2D
with:
24 filters
3 Γ 3 kernel
Convolution Block 2
Conv2D
BatchNormalization
MaxPooling2D
with:
48 filters
3 Γ 3 kernel
Fully Connected Layers
After convolution and pooling:
Flatten
β
Dense(1024)
β
Dropout(0.4)
β
Dense(1024)
β
Dropout(0.4)
β
Dense(1)
The final neuron produces the predicted PV output.
βοΈ Training Configuration
The model uses:
Optimizer: Adam
Learning Rate: 3e-6
Loss Function: Mean Squared Error
Batch Size: 256
Maximum Epochs: 200
Early stopping is used to prevent unnecessary training when validation performance stops improving.
π 10-Fold Cross-Validation
The notebook uses:
10-Fold Cross-Validation
However, instead of randomly splitting individual timestamps, the data is shuffled in day blocks.
This is particularly important for time-dependent solar forecasting because samples from the same day can be highly correlated.
The workflow is:
Timestamp Data
β
Day-Based Blocks
β
Shuffle Blocks
β
10-Fold Cross Validation
β
Training / Validation
πΎ Model Checkpoints
The best model from every fold is saved separately.
The structure is approximately:
model_output/
βββ SUNSET_nowcast_2017_2019_data/
βββ repetition_1/
β βββ best_model_repitition_1.h5
βββ repetition_2/
β βββ best_model_repitition_2.h5
βββ ...
βββ repetition_10/
βββ best_model_repitition_10.h5
Training and validation histories are also stored for later analysis.
π€ Ensemble Prediction
After training 10 models, predictions from all models are combined.
The final prediction is calculated using the mean:
Ensemble Prediction =
Mean(Prediction Model 1 ... Prediction Model 10)
This ensemble approach helps reduce the variance of individual models and provides a more stable final prediction.
βοΈ Sunny vs Cloudy Evaluation
The test dataset is further divided into:
Sunny Days
Cloudy Days
The model is evaluated separately on both conditions.
The notebook calculates:
Sunny RMSE
Cloudy RMSE
Overall RMSE
Sunny MAE
Cloudy MAE
Overall MAE
This is particularly useful because cloud conditions can introduce significant uncertainty into solar PV forecasting.
π Visualization
The notebook compares:
Ground Truth PV Output
vs
SUNSET Nowcast Prediction
for both sunny and cloudy days.
Each visualization includes:
Actual PV output
Predicted PV output
RMSE
MAE
Hour of the day
This allows the performance of the model to be analyzed throughout the day.
π§° Technologies & Libraries
Machine Learning
Python
NumPy
Pandas
Scikit-learn
Random Forest
XGBoost
SciPy
Deep Learning
TensorFlow
Keras
CNN
Adam Optimizer
Data Processing
HDF5
h5py
category_encoders
StandardScaler
Target Encoding
Visualization
Matplotlib
Seaborn
ποΈ Overall Architecture
Renewable Energy Data
β
ββββββββββββββββΌβββββββββββββββ
β β β
βΌ βΌ βΌ
Wind Data Solar Data Image Data
β β β
βΌ βΌ βΌ
Feature Engineering Time Encoding Image Processing
β β β
βΌ βΌ βΌ
Random Forest RF + XGBoost CNN
β β β
βΌ βΌ βΌ
Power Output Solar Irradiance PV Nowcasting
β β β
ββββββββββββββββΌβββββββββββββββ
βΌ
Performance Analysis
β
ββββββββ΄βββββββ
βΌ βΌ
MAE RMSE
β
βΌ
RΒ²
π Suggested Repository Structure
Renewable-Energy-Forecasting/
β
βββ notebooks/
β βββ wind_power_random_forest.ipynb
β βββ solar_irradiance_rf_xgboost.ipynb
β βββ sunset_pv_nowcasting_cnn.ipynb
β
βββ data/
β βββ Wind.csv
β βββ europe_cities_pvgis_data_slope_45_azimuth_180(in).csv
β βββ data_nowcast/
β βββ nowcast_dataset.hdf5
β βββ times_trainval.npy
β βββ times_test.npy
β
βββ model_output/
β βββ SUNSET_nowcast_2017_2019_data/
β
βββ README.md
π How to Run
1. Clone the repository
git clone <YOUR_REPOSITORY_URL>
cd Renewable-Energy-Forecasting
2. Install dependencies
pip install numpy pandas matplotlib seaborn scikit-learn scipy
pip install xgboost category_encoders
pip install tensorflow h5py
3. Prepare the datasets
Place the required datasets inside the appropriate data/ directories.
Update the dataset paths in the notebooks if necessary.
For example:
df = pd.read_csv("path/to/Wind.csv")
β οΈ Notes
The notebooks were originally developed for specific datasets and directory structures.
Therefore, dataset paths may need to be modified depending on the local environment.
The third model, in particular, requires:
HDF5 dataset
Timestamp files
Sufficient RAM
TensorFlow-compatible environment
GPU recommended for faster training
π Model Comparison
Aspect Wind RF Solar RF/XGBoost SUNSET CNN
Data Type Tabular Tabular Image + PV
Task Regression Regression Nowcasting
Main Target Wind Power Solar Irradiance PV Output
Main Models Random Forest RF + XGBoost CNN
Feature Engineering Temporal Temporal + City Image Processing
Hyperparameter Search No RandomizedSearchCV Manual Configuration
Cross Validation Standard Split Standard Split 10-Fold Day-Based
Ensemble No No Yes
Error Analysis Yes Yes Yes
Sunny/Cloudy Analysis No No Yes
π― Project Goals
The main goals of these implementations are:
Apply machine learning to renewable energy forecasting.
Predict wind power generation from meteorological data.
Predict solar irradiance using environmental and temporal features.
Compare Random Forest and XGBoost regression models.
Apply hyperparameter optimization using RandomizedSearchCV.
Apply deep learning to image-based solar PV nowcasting.
Use CNNs to extract spatial features from solar imagery.
Use day-based cross-validation for time-dependent data.
Improve prediction robustness through ensemble learning.
Analyze model errors under different weather conditions.
π¨βπ» Author & Modifications
Author: Momen
The notebooks in this repository were reviewed, modified, organized, and adapted by Momen.
The modifications focus on improving:
Data preprocessing
Feature engineering
Model configuration
Hyperparameter optimization
Training workflows
Model evaluation
Error analysis
Visualization
Ensemble prediction
Code organization
The implementations are intended for educational, experimental, and research purposes in the field of renewable energy forecasting and AI-based energy systems.
π License
This project is intended for educational and research purposes.