Appliance energy forecasting (CNN-LSTM ensemble)
Forecasts a house's appliance energy use (Wh) for the next 10 minutes, from the previous readings.
Try it in the live demo: huggingface.co/spaces/NethranjaliSE/appliance-energy-forecasting
Model
- Input: the last 2 hours (12 steps of 10 minutes) of 10 engineered features: the latest readings, their recent change, 1-hour and 3-hour rolling averages and spread, and time of day.
- Architecture: 1D convolution (32 filters, kernel 3) → LSTM (64 units) → dropout (0.3) → dense (32, ReLU) → linear output.
- Ensemble: three such networks trained with different random seeds; their forecasts are averaged.
- Training: Adam (learning rate 0.001, batch size 64), mean squared error on the standardised log of consumption, early stopping on a validation period.
Files
| File | Contents |
|---|---|
models/final_ensemble.keras | the three networks combined; outputs Wh directly |
models/scaler.joblib | the feature scaler fitted on the training data |
models/config.json | the selected feature names and the window length |
feature_engineering.py | builds the features from the raw readings |
predict.py | loads everything above and makes predictions |
How to use
Requires tensorflow, pandas, numpy, scikit-learn and huggingface_hub.
import sys
import pandas as pd
from huggingface_hub import snapshot_download
path = snapshot_download("NethranjaliSE/appliance-energy-cnn-lstm")
sys.path.append(path)
from predict import EnergyPredictor
predictor = EnergyPredictor(f"{path}/models")
# df: readings with the same columns as the UCI dataset, indexed by timestamp at 10-minute steps
df = pd.read_csv("energydata_complete.csv", parse_dates=["date"]).set_index("date")
predictor.predict(df) # a forecast for every interval with enough history
predictor.predict_next(df) # the forecast for the 10 minutes after the last reading
The input needs at least about 26 hours of history: 24 hours for the daily lag feature plus the 2-hour window.
Results
Test period: 30 April to 27 May 2016, the last 20% of the data in time order, never used for training or model selection.
| Model | MAE (Wh) | RMSE (Wh) | MAPE (%) | R² |
|---|---|---|---|---|
| Repeat the last reading | 26.05 | 65.19 | 21.86 | 0.45 |
| Linear Regression | 27.26 | 66.49 | 22.12 | 0.43 |
| Random Forest | 26.51 | 58.30 | 23.19 | 0.56 |
| LSTM | 23.41 | 56.78 | 19.38 | 0.58 |
| CNN-LSTM ensemble (this model) | 22.80 | 55.71 | 19.01 | 0.60 |
Limitations
- It follows the daily routine well but usually underestimates sudden spikes, which often begin with no warning in the previous readings.
- It was trained on one house in Belgium over 4.5 months (January to May 2016). It will not transfer to other homes or seasons without retraining.
- The holiday feature covers Belgian public holidays in 2016 only.
Data
Candanedo, L. M., Feldheim, V. and Deramaix, D. (2017). Data driven prediction models of energy use of appliances in a low-energy house. Energy and Buildings, 140, 81-97.
Dataset: UCI Machine Learning Repository, licensed CC BY 4.0.