KALYAN1188/Household-Energy-Consumption-Predictor
π Predicting Appliance Energy Consumption In Households
   
ML-powered household energy consumption prediction with comprehensive insights for energy optimization, cost reduction, and grid management.
π― Project Overview
Our client, an energy management company, aims to enhance their understanding of appliance energy consumption patterns in residential settings. This project leverages machine learning to predict appliance energy usage based on various environmental and household factors.
π Project Benefits
π Model Performance
Interpretation: Model explains 70% of energy variance with average error of Β±14.27 Wh. Negative overfit gap indicates excellent generalization β model performs better on unseen data!
π Live Demo
Try the live application here: π [Hugging Face Space](https://huggingface.co/spaces/YOUR_USERNAME/energy-consumption-predictor)
π Project Structure
household-energy-prediction/
βββ notebook.ipynb # Complete ML pipeline (12 steps)
βββ app.py # Gradio deployment app
βββ final_model.pkl # Trained model package
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ energydata_complete.csv # Dataset
βββ outputs/ # Generated visualizations
βββ 01_target_analysis.png
βββ 02_feature_distributions.png
βββ 03_correlation_analysis.png
βββ 04_time_patterns.png
βββ 05_scatter_plots.png
βββ 06_room_analysis.png
βββ 07_lights_analysis.png
βββ 08_weather_analysis.png
βββ 09_multicollinearity.png
βββ 10_consumption_categories.png
βββ 11_outlier_handling.png
βββ 12_feature_engineering.png
βββ 13_model_comparison.png
βββ 14_cross_validation.png
βββ 15_feature_importance.png
βββ 16_shap_importance.png
βββ 17_shap_beeswarm.png
βββ 18_error_analysis.pngπ οΈ Installation
Prerequisites
- Python 3.11 or higher
- pip package manager
Step 1: Clone Repository
git clone https://github.com/YOUR_USERNAME/household-energy-prediction.git
cd household-energy-predictionStep 2: Create Virtual Environment (Recommended)
# Create virtual environment
python -m venv venv
# Activate β Windows:
venv\Scripts\activate
# Activate β Mac/Linux:
source venv/bin/activateStep 3: Install Dependencies
pip install -r requirements.txtπ How to Reproduce
Option 1: Run Complete Training Pipeline
# Step 1: Open Jupyter notebook
jupyter notebook notebook.ipynb
# Step 2: Run all cells from top to bottom
# The notebook will automatically:
# - Load and clean data
# - Perform comprehensive EDA (11 sections)
# - Engineer 40+ features including lag features
# - Train 14 different models
# - Perform hyperparameter tuning
# - Run time series cross-validation
# - Generate SHAP analysis
# - Create 18 visualizations
# - Save final model as final_model.pkl
# Step 3: Wait for completion (~15-20 minutes)
# Step 4: Check outputs/ folder for all generated plotsOption 2: Use Pre-trained Model
# Run Gradio app directly
python app.pyThis launches the interface at http://localhost:7860
π¬ Methodology
1. Data Overview
- Dataset: 19,735 records at 10-minute intervals (JanβMay 2016)
- Target:
Appliancesβ energy use in Wh - Features: 29 original β 40+ after engineering
- Missing Values: None β
- Duplicate Rows: None β
2. Data Split Strategy
TIME-BASED SPLIT (respects temporal order):
βββ Train : 70% β JanβMar 2016
βββ Val : 15% β MarβApr 2016
βββ Test : 15% β AprβMay 2016
β
Split done BEFORE any preprocessing (zero data leakage)
β
No shuffle β preserves time series order3. Exploratory Data Analysis (11 Sections)
4. Feature Engineering (40+ Features)
Time Features:
- Hour, day of week, month, day
- Is weekend, is night, is peak hour
- Minute of day
Temperature & Humidity Aggregates:
- Average/max/min indoor temperature
- Indoor temperature range
- Indoor vs outdoor differential
Interaction Features:
- Temperature Γ Humidity
- Temperature Γ Hour
- Lights Γ Hour
Lag Features (Most Important!):
- lag1 to lag12 (10 min to 2 hours ago)
- lag_144 (1 day ago)
- lag_288 (2 days ago)
Rolling Window Features:
- Rolling mean (3, 6, 12, 24 intervals)
- Rolling std, max, min (6 intervals)
5. Outlier Handling
Strategy:
βββ Train : REMOVE outliers (IQR method, multiplier=1.5)
βββ Val : CAP outliers at bounds
βββ Test : CAP outliers at bounds
Bounds computed on TRAIN ONLY β applied to Val/Test6. Model Training & Comparison
Evaluated 14 regression models:
Best Model: Lasso Regression
- Val RΒ²: 0.672 (highest among all models)
- Overfit Gap: -0.047 (no overfitting!)
7. Hyperparameter Tuning
Method : RandomizedSearchCV
CV : 5-Fold Time Series Split
Iterations: 50
Scoring : RΒ²
Best Alpha: 0.18. Model Evaluation
A) Time Series Cross-Validation (5-Fold):
RΒ² Mean : 0.6050 Β± 0.0622
MSE Mean : 305.41 Β± 55.23
RMSE Mean: 17.45 Β± 1.60
MAE Mean : 12.07 Β± 0.87
B) SHAP Analysis:
- LinearExplainer for interpretability
- Lag features dominate importance
- Rolling features second most important
C) Comprehensive Error Analysis:
- 9-plot error visualization
- Error by price range
- Cumulative error distribution9. Key Findings
- Lag features are the strongest predictors β what happened in the last 10-60 minutes best predicts current usage
- Linear models outperform tree models β lag features create linear relationships
- Peak hours (5-9PM) show highest energy consumption
- Energy is 57% higher when lights are ON vs lights off
- No overfitting β model generalizes perfectly to unseen data
10. Deployment
- Framework: Gradio 5.10.0
- Features:
- 5 output tabs (Prediction, Cost, Grid, Tips, Summary)
- Real-time cost estimation in βΉ
- Peak hour warnings
- Personalized energy saving tips
- Grid management recommendations
- COβ emissions tracking
- Platform: Hugging Face Spaces
π Visualizations Generated
π Troubleshooting
Model Loading Issues
import joblib, sklearn
print(f"sklearn version: {sklearn.__version__}")
# Should be 1.6.1SHAP Installation Issues
# Windows
pip install shap --no-build-isolation
# Linux/Mac
pip install shapGradio Version Issues
pip install gradio==5.10.0π Future Improvements
- [ ] Add more data sources (smart meter data)
- [ ] Implement occupancy detection features
- [ ] Real-time data streaming
- [ ] Mobile app deployment
- [ ] API for third-party integration
- [ ] Advanced deep learning models (LSTM)
π€ Contributing
Contributions are welcome!
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
π License
This project is licensed under the MIT License.
π¨βπ» Developer
Sai Kalyan Machine Learning Engineer
- π§ Email: kalyan.kothwal@gmail.com
- πΌ LinkedIn: Your LinkedIn
- π GitHub: Your GitHub
- π Portfolio: Your Portfolio
π References
- UCI Machine Learning Repository β Appliances Energy Prediction Dataset
- Candanedo, L.M., Feldheim, V., Deramaix, D. (2017). "Data driven prediction models of energy use of appliances in a low-energy house"
- SHAP: Lundberg, S.M., & Lee, S.I. (2017). "A Unified Approach to Interpreting Model Predictions"
- Lasso Regression: Tibshirani, R. (1996). "Regression Shrinkage and Selection via the Lasso"
β If you found this project helpful, please give it a star!
Last Updated: March 2026 | Version: 1.0
