A comprehensive machine learning toolkit for building energy consumption prediction, featuring advanced LSTM models with Firefly Algorithm optimization and support for multiple datasets.
This project implements and evaluates various energy prediction models including:
- ModLSTM: Modified LSTM with Firefly Algorithm optimization
- Standard LSTM: Baseline LSTM implementation
- SAMFOR: Sequential Attention-based Model for Forecasting
- SVR/RFR: Support Vector Regression and Random Forest baselines
The toolkit supports two datasets:
- Portuguese Dataset: Single-household energy consumption data
- ASHRAE Dataset: Multi-building commercial energy consumption data
Energy-Prediction/
βββ models/ # Model implementations
β βββ LSTM_comb.py # Main LSTM training pipeline
β βββ LSTM_hyperpara_search.py # Firefly Algorithm hyperparameter optimization
β βββ SAMFOR_trial1.py # SAMFOR model implementation
β βββ SVR_energy_data_paper2.py # SVR/RFR baseline models
βββ tools/ # Data preprocessing utilities
β βββ preprocess_data2.py # Shared utilities for Portuguese dataset
β βββ preprocessing_ashrae.py # ASHRAE-specific preprocessing
β βββ resample_dataset.py # Data resampling utilities
βββ dataset/ # Datasets
β βββ 1Hz/ # Original Portuguese dataset (1Hz)
β βββ resampled data/ # Resampled Portuguese data
β βββ ASHRAE/ # ASHRAE Great Energy Predictor III dataset
βββ results/ # Model outputs and results
β βββ 1s/ # Portuguese dataset results
β βββ ashrae/ # ASHRAE dataset results
βββ niapy/ # Firefly Algorithm implementation
βββ config.py # Configuration settings
- Python 3.8+
- TensorFlow/Keras
- scikit-learn
- pandas, numpy
- matplotlib, seaborn
- Clone the repository:
git clone <repository-url>
cd Energy-Prediction- Create a virtual environment:
conda create -n FF python=3.8
conda activate FF- Install dependencies:
pip install tensorflow keras scikit-learn pandas numpy matplotlib seaborn- Train LSTM model:
python models/LSTM_comb.py- Run hyperparameter optimization:
python models/LSTM_hyperpara_search.py- Train baseline models:
python models/SVR_energy_data_paper2.py
python models/SAMFOR_trial1.py- Generate comparative results:
python plot_results.py- SVR baseline (disjoint buildings)
conda run -n FF python -m ashrae.call_svr_ashrae- SAMFOR baseline
conda run -n FF python -m ashrae.call_samfor_ashrae- LSTM Hyperparameter Search (overnight)
conda run -n FF python -m ashrae.call_lstm_search_ashraeAll ASHRAE models now use a centralized results saving system:
results/ashrae/
βββ svr/
β βββ metrics.csv # Model performance metrics
β βββ model_info.json # Model parameters and metadata
β βββ artifacts/
β βββ SVR_ASHRAE.obj # Unscaled predictions and test data
βββ samfor/
β βββ metrics.csv
β βββ model_info.json
β βββ artifacts/
β βββ SAMFOR.obj
βββ lstm/
βββ metrics.csv # LSTM results (from log_results_LSTM)
βββ model_info.json # Best parameters and metadata
βββ training_log.json # Training history and convergence
βββ artifacts/
βββ LSTM_ModFF.obj # Unscaled predictions and test data
Standardized Artifacts Include:
- Unscaled ground truth (
y_test) and predictions (y_test_pred) - Model parameters, timing, and metadata
- Consistent file naming and structure across all models
- Source: Single-household energy consumption data
- Frequency: 1Hz (resampled to 1s)
- Features: Power consumption measurements
- Preprocessing: MinMax scaling, sliding window sequencing
- Sequence Length: 23 timesteps
- Source: ASHRAE Great Energy Predictor III (Kaggle)
- Scope: Multi-building commercial energy consumption
- Features: Building metadata, weather data, temporal features
- Preprocessing: MinMax scaling (fit on train only), one-hot encoding;
building_idpreserved and not scaled for windowing - Sequence Length: 23 timesteps
- Sample Size: ~130,000 total windows using disjoint building splits (Trainβ52k, Valβ26k, Testβ52k)
- Resampling: None for ASHRAE 1s/1Hz; dataset already at target granularity
- ModLSTM: Modified LSTM architecture with optimized hyperparameters
- Firefly Algorithm: Bio-inspired optimization for hyperparameter tuning
- Early Stopping: Prevents overfitting during training
- Sequence-to-One: Predicts next timestep energy consumption
- Feature Engineering: Temporal, building, and weather features
- Missing Value Imputation: Mean imputation for numerical features
- Normalization: Dataset-specific scaling (MinMax vs Z-score)
- Sequential Cropping: Time-series consistent data sampling
- RMSE: Root Mean Square Error
- MAE: Mean Absolute Error
- MAPE: Mean Absolute Percentage Error
- RMSLE: Root Mean Squared Logarithmic Error
- RΒ²: Coefficient of Determination
Building energy consumption prediction is crucial for:
- Smart Grid Management: Optimizing energy distribution and demand response
- Building Optimization: Improving HVAC system efficiency and occupant comfort
- Sustainability Goals: Supporting Net-Zero Energy Building (NZEB) initiatives
- Cost Reduction: Minimizing energy costs through predictive maintenance
- Temporal Dependencies: Energy consumption exhibits complex time-series patterns
- Multi-scale Variability: Patterns vary across hours, days, seasons, and years
- External Factors: Weather, occupancy, and building characteristics significantly impact consumption
- Data Quality: Missing values, outliers, and measurement errors in sensor data
- Generalizability: Models trained on single buildings may not generalize to diverse building types
- LSTM Networks: Capture long-term dependencies in time-series data
- ModLSTM: Enhanced LSTM with optimized architecture for energy prediction
- Firefly Algorithm: Bio-inspired optimization for hyperparameter tuning
- Attention Mechanisms: Focus on relevant temporal patterns (SAMFOR)
- Ensemble Methods: Combine multiple models for robust predictions
Key hyperparameters (from Table II):
- LSTM Units: 72
- Learning Rate: 0.010
- Sequence Length: 23
- Batch Size: 64
- Epochs: 50 (with early stopping)
- Data Loading: Load raw datasets
- Merging: Join building metadata and weather data
- Feature Engineering: Create temporal and categorical features
- Normalization: Apply dataset-specific scaling
- Sequencing: Generate sliding window sequences for LSTM
- Splitting: Train/validation/test splits
- Model Building: Construct LSTM architecture
- Compilation: Configure optimizer and loss function
- Training: Fit model with early stopping
- Evaluation: Compute metrics on test set
- Persistence: Save model and results
This toolkit addresses a critical limitation in energy prediction research: Limited Dataset Diversity. Most studies focus on single buildings or homogeneous datasets, limiting model generalizability.
Our Approach:
- Multi-Dataset Validation: Portuguese residential + ASHRAE commercial data
- Diverse Building Types: Single-family homes vs. multi-building commercial complexes
- Different Climates: Portuguese climate vs. multiple US climate zones
- Varied Meter Types: Electricity vs. multiple utility types (electricity, chilled water, steam, hot water)
- Scale Differences: Single building vs. thousands of buildings
- Unified Preprocessing Pipeline: Consistent feature engineering across datasets
- Adaptive Normalization: Dataset-specific scaling strategies
- Memory-Efficient Processing: Sequential cropping for large datasets
- Comprehensive Evaluation: Multiple metrics on original-scale data
- Reproducible Research: Complete preprocessing and training pipelines
Building energy consumption prediction has evolved from simple regression models to sophisticated deep learning approaches. Key developments include:
- Traditional Methods: Linear regression, ARIMA, and support vector machines
- Machine Learning: Random forests, gradient boosting, and neural networks
- Deep Learning: LSTM, GRU, and transformer-based models
- Hybrid Approaches: Combining physical models with data-driven methods
Energy consumption exhibits unique characteristics:
- Seasonality: Daily, weekly, and annual patterns
- Non-stationarity: Changing patterns over time
- External Dependencies: Weather, occupancy, and building operations
- Multi-scale Dynamics: Short-term fluctuations and long-term trends
Hyperparameter optimization is crucial for model performance:
- Grid Search: Exhaustive but computationally expensive
- Random Search: More efficient than grid search
- Bayesian Optimization: Model-based optimization
- Bio-inspired Algorithms: Firefly, particle swarm, genetic algorithms
- ASHRAE Great Energy Predictor III: Kaggle Competition
- Firefly Algorithm: Yang, X.S. (2008). Nature-Inspired Metaheuristic Algorithms
- LSTM Networks: Hochreiter, S. & Schmidhuber, J. (1997). Long Short-Term Memory
- Energy Prediction: Ahmad, T. et al. (2018). A review on renewable energy and electricity requirement forecasting
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Memory Errors: Reduce
max_samplesin preprocessing - Import Errors: Ensure all dependencies are installed
- Path Issues: Check dataset paths in configuration files
- CUDA Issues: Verify TensorFlow GPU installation
For issues and questions:
- Check the troubleshooting section
- Review the preprocessing reports
- Examine the test scripts for examples
Note: This toolkit is designed for research purposes and addresses the challenge of limited dataset diversity in energy prediction research.