A machine learning application that predicts the heating load of buildings based on their architectural characteristics. This tool helps architects, engineers, and energy consultants estimate energy requirements during the building design phase.
- Overview
- Features
- Demo
- Dataset
- Models & Performance
- Project Structure
- Prerequisites
- Installation
- Running the Application
- Using the Web App
- Running the Jupyter Notebook
- Technical Details
- Troubleshooting
- Future Improvements
- License
This project uses regression models with polynomial feature engineering to predict building heating loads. The best performing model achieves an R² score of 0.99, meaning it explains 99% of the variance in heating load predictions.
- Energy Efficiency: Helps optimize building designs for lower energy consumption
- Cost Savings: Accurate predictions enable better HVAC system sizing
- Sustainability: Supports green building initiatives by identifying energy-efficient designs
- Interactive Web Interface: User-friendly Gradio app with sliders for all building parameters
- Multiple Models: Compare predictions across 9 different model configurations
- Model Selection: Choose between Ridge, Lasso, and ElasticNet regression
- Polynomial Features: Models trained with degrees 1, 2, and 3 for capturing non-linear relationships
- Energy Efficiency Rating: Automatic classification of predicted heating load
- Performance Metrics: View R² scores and compare model accuracy
Live Demo on Hugging Face Spaces (Coming Soon)
Source: UCI Machine Learning Repository - Energy Efficiency Dataset
| Property | Value |
|---|---|
| Samples | 768 buildings |
| Features | 8 input variables |
| Target | Heating Load (kWh/m² per year) |
| Missing Values | None |
| Feature | Description | Range |
|---|---|---|
| Relative Compactness | Volume-to-surface area ratio | 0.62 - 0.98 |
| Surface Area | Total exterior surface area (m²) | 514.5 - 808.5 |
| Wall Area | Total wall area (m²) | 245.0 - 416.5 |
| Roof Area | Roof area (m²) | 110.25 - 220.5 |
| Overall Height | Building height (m) | 3.5 - 7.0 |
| Orientation | Building orientation (2=N, 3=E, 4=S, 5=W) | 2 - 5 |
| Glazing Area | Window-to-floor area ratio | 0.0 - 0.4 |
| Glazing Area Distribution | Window distribution across facades | 0 - 5 |
| Variable | Description | Range |
|---|---|---|
| Heating Load | Annual heating energy requirement (kWh/m²) | 6.01 - 43.10 |
All models were evaluated using 5-Fold Cross-Validation.
| Model | Polynomial Degree | R² Score | Accuracy |
|---|---|---|---|
| Lasso | 3 | 0.9921 | 99.21% |
| Ridge | 3 | 0.9931 | 99.31% |
| ElasticNet | 3 | 0.9753 | 97.53% |
| Lasso | 2 | 0.9608 | 96.08% |
| Ridge | 2 | 0.9620 | 96.20% |
| ElasticNet | 2 | 0.9517 | 95.17% |
| Lasso | 1 | 0.9237 | 92.37% |
| Ridge | 1 | 0.9240 | 92.40% |
| ElasticNet | 1 | 0.9230 | 92.30% |
Best Model: Lasso Regression with Polynomial Degree 3
Building Energy Efficiency Predictor/
│
├── app.py # Gradio web application
├── save_model.py # Script to train and save all models
├── load_model.py # Example script for loading saved models
├── building_energy_efficiency_predictor.ipynb # Jupyter notebook with full analysis
├── ENB2012_data.csv # Dataset
├── requirements.txt # Python dependencies
├── README.md # This file
│
├── models/ # Saved trained models
│ ├── ridge_degree1.joblib
│ ├── ridge_degree2.joblib
│ ├── ridge_degree3.joblib
│ ├── lasso_degree1.joblib
│ ├── lasso_degree2.joblib
│ ├── lasso_degree3.joblib
│ ├── elasticnet_degree1.joblib
│ ├── elasticnet_degree2.joblib
│ ├── elasticnet_degree3.joblib
│ └── all_models_metadata.joblib
│
└── .venv/ # Virtual environment (not in repo)
Before you begin, ensure you have the following installed:
- Python 3.8 or higher - Download Python
- pip - Python package installer (comes with Python)
- Git - For cloning the repository - Download Git
Open a terminal/command prompt and run:
python --version
# Should output: Python 3.8.x or higher
pip --version
# Should output: pip 21.x.x or higherDownload the ZIP file from GitHub and extract it, or clone using Git:
git clone <repository-url>
cd building-energy-efficiency-predictorCreating a virtual environment keeps project dependencies isolated.
On Windows:
python -m venv .venv
.venv\Scripts\activateOn macOS/Linux:
python3 -m venv .venv
source .venv/bin/activateYou should see (.venv) at the beginning of your terminal prompt.
pip install -r requirements.txtThis will install:
- pandas
- numpy
- matplotlib
- scikit-learn
- seaborn
- joblib
- gradio
If the models/ folder is empty or missing, you need to train the models:
python save_model.pyExpected output:
Training and saving all models...
==================================================
[OK] Ridge (Degree 1) - R2: 0.9240
[OK] Lasso (Degree 1) - R2: 0.9237
[OK] ElasticNet (Degree 1) - R2: 0.9230
[OK] Ridge (Degree 2) - R2: 0.9620
[OK] Lasso (Degree 2) - R2: 0.9608
[OK] ElasticNet (Degree 2) - R2: 0.9517
[OK] Ridge (Degree 3) - R2: 0.9931
[OK] Lasso (Degree 3) - R2: 0.9921
[OK] ElasticNet (Degree 3) - R2: 0.9753
==================================================
[OK] All 9 models saved to models/ directory
[OK] Metadata saved to models/all_models_metadata.joblib
python app.pyExpected output:
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Open your web browser and go to:
http://127.0.0.1:7860
or
http://localhost:7860
Press Ctrl + C in the terminal to stop the server.
The app has 4 tabs:
- Select a Model from the dropdown (default: Lasso Degree 3)
- Adjust Building Parameters using the sliders:
- Relative Compactness
- Surface Area
- Wall Area
- Roof Area
- Overall Height
- Orientation
- Glazing Area
- Glazing Area Distribution
- Click "Predict Heating Load"
- View the prediction result and energy efficiency rating
- Set your building parameters
- Click "Compare All Models"
- See predictions from all 9 models side-by-side
- Compare R² scores to understand model reliability
- View all models ranked by R² score
- Read explanations of Ridge, Lasso, and ElasticNet
- Understand polynomial feature engineering
- Project overview
- Dataset information
- Technical approach
- Best model statistics
The notebook contains the complete analysis including:
- Exploratory Data Analysis (EDA)
- Data visualization
- Model training and evaluation
- Cross-validation results
jupyter notebook building_energy_efficiency_predictor.ipynbOr use JupyterLab:
jupyter labIn Jupyter:
- Click Kernel → Restart & Run All
- Wait for all cells to execute
- View visualizations and results
- Column Cleaning: Removed trailing whitespace from column names
- Feature Scaling: StandardScaler for numerical features
- Encoding: OneHotEncoder for categorical features (Orientation, Glazing Distribution)
- Feature Engineering: PolynomialFeatures for degrees 1, 2, and 3
Input Data → Preprocessing → Polynomial Features → Regularized Regression → Prediction
| Model | Regularization | Key Property |
|---|---|---|
| Ridge | L2 (squared coefficients) | Shrinks all coefficients |
| Lasso | L1 (absolute coefficients) | Can set coefficients to zero (feature selection) |
| ElasticNet | L1 + L2 combined | Balance of both approaches |
- Method: 5-Fold Cross-Validation
- Metric: R² Score (Coefficient of Determination)
- Purpose: Robust evaluation, prevents overfitting
Solution: Install the missing package:
pip install xxxOr reinstall all requirements:
pip install -r requirements.txtSolution: Retrain the models with your current sklearn version:
python save_model.pySolution: Either:
- Stop the other process using port 7860
- Or modify
app.pyto use a different port:app.launch(server_port=7861)
Solution:
- Clear browser cache
- Try a different browser
- Check terminal for error messages
Windows Solution:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
.venv\Scripts\activatemacOS/Linux Solution:
source .venv/bin/activateThis project is licensed under the MIT License - see the LICENSE file for details.
If you find this project helpful, please give it a star on GitHub!