EnerSense AI is a machine learning project designed to forecast building electricity consumption, analyze energy usage patterns, and identify unusual consumption behavior.
The project combines historical electricity consumption, weather conditions, and time-based features to build an intelligent energy forecasting system.
Building energy consumption changes according to time, weather, operational patterns, and historical demand.
EnerSense AI uses historical hourly electricity consumption along with weather and temporal features to:
- Forecast hourly electricity consumption
- Analyze energy consumption patterns
- Detect unusual consumption points
- Compare machine learning models
- Identify the most important prediction features
- Provide an interactive Streamlit dashboard
The project focuses on a selected building:
Building: Hog_other_Tobias
Site: Hog
Building Type: Animal Shelter
Area: 2,220.7 mΒ²
The main objectives of this project are:
- Analyze historical building electricity consumption.
- Study energy consumption patterns over time.
- Integrate electricity and weather data.
- Handle missing values and prepare the dataset.
- Perform exploratory data analysis.
- Detect potential energy consumption anomalies.
- Engineer time-series and lag-based features.
- Train multiple machine learning models.
- Compare model performance.
- Develop an interactive energy monitoring dashboard.
The project uses three major datasets:
Hourly electricity consumption data was used for the selected building.
Selected meter:
Hog_other_Tobias
Original readings:
17,544
Missing values:
0%
Building-level information includes:
- Building ID
- Site ID
- Primary space usage
- Sub-primary space usage
- Building area
- Latitude
- Longitude
- Timezone
- Electricity availability
- Year built
- EUI
- Site EUI
- Source EUI
- Other building characteristics
Selected building information:
| Attribute | Value |
|---|---|
| Building | Hog_other_Tobias |
| Site | Hog |
| Primary Usage | Other |
| Sub Usage | Animal Shelter |
| Area | 2,220.7 mΒ² |
| Electricity | Yes |
| EUI | 76.4 |
| Site EUI | 161.3 |
| Source EUI | 75.1 |
| Timezone | US/Central |
Weather information was integrated using the building's site.
Important weather variables include:
- Air Temperature
- Dew Temperature
- Precipitation
- Sea Level Pressure
- Wind Direction
- Wind Speed
- Cloud Coverage
The initial merged dataset contained:
Shape:
(17,544, 11)
Missing values were found in several weather variables.
Missing values were handled during preprocessing.
The cleaned dataset contains:
Shape:
(17,544, 15)
Remaining missing values:
0
The final dataset contains:
- Timestamp
- Energy Consumption
- Site ID
- Weather features
- Hour
- Day
- Day of week
- Month
- Year
- Weekend indicator
Several analyses were performed to understand energy consumption behavior.
| Statistic | Value |
|---|---|
| Mean | 37.50 |
| Median | 36.05 |
| Minimum | 8.83 |
| Maximum | 76.70 |
| Standard Deviation | 12.50 |
- Energy consumption varies significantly throughout the year.
- Consumption shows clear hourly patterns.
- Energy demand is generally higher during morning and evening periods.
- Weekday average consumption is slightly higher than weekend consumption.
- Energy consumption changes with temperature and seasonal conditions.
- Monthly consumption shows noticeable variation across the two-year period.
The analysis shows a strong daily consumption pattern.
Higher average consumption was observed around:
- 06:00
- 07:00
- 18:00
- 19:00
Lower consumption was generally observed during:
- Early morning
- Late evening
This indicates that time-based features are important for forecasting energy demand.
Daily and monthly aggregation was performed to identify long-term consumption trends.
The analysis covered:
January 2016 β December 2017
Monthly consumption showed noticeable seasonal changes, with higher and lower consumption periods across the year.
Weather variables were analyzed against electricity consumption.
Correlation with energy consumption:
| Feature | Correlation |
|---|---|
| Air Temperature | -0.4798 |
| Dew Temperature | -0.4544 |
| Month | -0.2291 |
| Sea Level Pressure | 0.1055 |
| Wind Direction | 0.1025 |
| Hour | 0.0805 |
| Wind Speed | 0.0583 |
| Precipitation | -0.0366 |
| Is Weekend | -0.0468 |
Air temperature showed the strongest negative correlation among the analyzed variables.
Potential unusual energy consumption points were identified using an IQR-based approach.
- Lower Bound:
-2.03 - Upper Bound:
75.02 - Potential anomalies:
2 - Anomaly percentage:
0.01%
Example high-consumption observations included:
| Timestamp | Energy Consumption |
|---|---|
| 2016-01-31 05:00 | 76.700 |
| 2016-04-13 19:00 | 75.889 |
These observations can be investigated further to determine whether they were caused by operational activity, weather conditions, equipment behavior, or other factors.
Time-series features were created to improve forecasting performance.
hourdayday_of_weekmonthyearis_weekend
lag_1hlag_2hlag_24hlag_168h
rolling_24hrolling_168h
These features allow the models to learn relationships between current consumption and previous consumption patterns.
Three machine learning models were evaluated:
- Random Forest
- Gradient Boosting
- HistGradientBoosting
The data was split chronologically to preserve the time-series structure.
| Dataset | Samples |
|---|---|
| Training | 13,900 |
| Testing | 3,476 |
| Total | 17,376 |
2016-01-08 00:00:00
to
2017-08-09 03:00:00
2017-08-09 04:00:00
to
2017-12-31 23:00:00
| Model | MAE | RMSE | RΒ² |
|---|---|---|---|
| HistGradientBoosting | 2.0751 | 3.0516 | 0.9258 |
| Gradient Boosting | 2.1311 | 3.1306 | 0.9219 |
| Random Forest | 2.2191 | 3.2675 | 0.9149 |
HistGradientBoosting
Performance:
- MAE: 2.0751
- RMSE: 3.0516
- RΒ²: 0.9258
- RΒ² Score: 92.58%
The model achieved the best performance among the evaluated models.
The most important features for the selected forecasting model were:
| Feature | Importance |
| lag_24h | 0.6628 |
| lag_1h | 0.2522 |
| rolling_24h | 0.0192 |
| lag_2h | 0.0129 |
| lag_168h | 0.0119 |
| hour | 0.0110 |
Historical energy consumption is the strongest predictor of future consumption.
In particular, lag_24h contributed approximately 66.3% of the model's feature importance, showing the importance of previous-day consumption patterns.
The selected HistGradientBoosting model produced:
- Average Absolute Error: 2.0751
- Maximum Absolute Error: 24.4964
Most predictions remain relatively close to the actual consumption values, while larger errors can help identify periods requiring additional investigation.
EnerSense AI includes a Streamlit dashboard for interactive energy monitoring.
The dashboard provides:
- Energy consumption overview
- Actual vs predicted consumption
- Daily energy consumption
- Prediction error analysis
- Anomaly monitoring
- Building information
- Model performance
- Feature information
- Energy insights
EnerSense-AI/ β βββ DASHBOARD/ β βββ app.py β βββ DATA/ β βββ electricity_cleaned.csv β βββ metadata.csv β βββ weather.csv β βββ energy_predictions.csv β βββ IMAGES/ β βββ dashboard.png β βββ actual_vs_predicted_energy.png β βββ anomaly monitoring.png β βββ daily avg energy_consumption.png β βββ model_comparison.png β βββ MODELS/ β βββ enerSense_histgradient_model.pkl β βββ model_features.pkl β βββ NOTEBOOK/ β βββ EnerSense_AI.ipynb β βββ SRC/ β βββ init.py β βββ data_preprocessing.py β βββ feature_engineering.py β βββ anomaly_detection.py β βββ model_utils.py β βββ .gitignore βββ REQUIREMENT.txt βββ README.md
- Python
- Pandas
- NumPy
- Scikit-learn
- Matplotlib
- Plotly
- Streamlit
- Jupyter Notebook
- Git & GitHub
git clone https://github.com/ashfiya015-stack/EnerSense-AI.git cd EnerSense-AI
pip install -r requirement.txt
streamlit run DASHBOARD/app.py
EnerSense AI includes an interactive Streamlit dashboard for monitoring building energy consumption, predictions, and anomalies.
- β‘ Energy consumption overview
- π Actual vs predicted energy consumption
- π Daily energy consumption trends
- π¨ Prediction-error based anomaly monitoring
- π’ Building information
- π€ AI model performance
- π‘ Energy consumption insights
- π Interactive date-range selection
Three machine learning models were evaluated for hourly energy consumption forecasting.
| Model | MAE | RMSE | RΒ² Score |
|---|---|---|---|
| HistGradientBoosting | 2.0751 | 3.0516 | 0.9258 |
| Gradient Boosting | 2.1311 | 3.1306 | 0.9219 |
| Random Forest | 2.2191 | 3.2675 | 0.9149 |
HistGradientBoosting achieved the best overall performance:
- RΒ² Score: 92.58%
- MAE: 2.0751
- RMSE: 3.0516
The model explains approximately 92.58% of the variation in the test-set energy consumption.
The model identified historical energy consumption as the strongest predictor.
| Feature | Importance |
|---|---|
lag_24h |
0.662767 |
lag_1h |
0.252241 |
rolling_24h |
0.019245 |
lag_2h |
0.012938 |
lag_168h |
0.011916 |
hour |
0.011035 |
The lag_24h feature was the most important feature, showing that energy consumption from the previous day strongly influences the current hourly demand.
EnerSense AI identifies unusual energy consumption using prediction errors.
- Original observations: 17,544
- Model-ready observations: 17,376
- Potential anomalies detected: 332 in the dashboard monitoring period
- Maximum absolute prediction error: 24.50
An observation is considered unusual when the difference between actual and predicted consumption exceeds the selected anomaly threshold.
| Metric | Value |
|---|---|
| Mean | 37.50 |
| Median | 36.05 |
| Minimum | 8.83 |
| Maximum | 76.70 |
| Standard Deviation | 12.50 |
Energy consumption shows a clear time-of-day pattern, with higher average consumption during morning and evening hours.
Average consumption:
- Weekdays: 37.87
- Weekends: 36.58
This indicates slightly higher energy consumption during weekdays.
Weather variables were incorporated into the analysis and forecasting pipeline.
The correlation analysis showed:
- Air temperature: -0.4798
- Dew temperature: -0.4544
- Sea-level pressure: 0.1055
- Wind direction: 0.1025
- Wind speed: 0.0583
Air temperature and dew temperature showed the strongest negative correlations with energy consumption among the weather variables.
The selected building used for this project is:
| Attribute | Value |
|---|---|
| Building | Hog_other_Tobias |
| Site | Hog |
| Building Type | Animal Shelter |
| Area | 2,220.7 mΒ² |
| Electricity | Yes |
| Timezone | US/Central |
| EUI | 76.4 |
| Site EUI | 161.3 |
| Source EUI | 75.1 |
The project follows the following workflow:
Raw Data β Data Loading β Data Cleaning β Missing Value Treatment β Exploratory Data Analysis β Feature Engineering β Time-Series Feature Creation β Train/Test Split β Model Training β Model Evaluation β Best Model Selection β Energy Forecasting β Anomaly Detection β Interactive Streamlit Dashboard
The following features were created for forecasting:
hour
day
day_of_week
month
year
is_weekend
lag_1h
lag_2h
lag_24h
lag_168h
rolling_24h
rolling_168h
Lag and rolling-window features capture historical consumption patterns and improve forecasting performance.
EnerSense-AI/ β βββ DASHBOARD/ β βββ app.py β βββ DATA/ β βββ electricity_cleaned.csv β βββ metadata.csv β βββ weather.csv β βββ energy_predictions.csv β βββ enerSense_building_data.csv β βββ IMAGES/ β βββ dashboard.png β βββ actual_vs_predicted_energy.png β βββ anomaly_monitoring.png β βββ daily_avg_energy_consumption.png β βββ model_comparison.png β βββ MODELS/ β βββ enerSense_histgradient_model.pkl β βββ model_features.pkl β βββ model_performance.csv β βββ NOTEBOOK/ β βββ EnerSense_AI.ipynb β βββ SRC/ β βββ init.py β βββ data_preprocessing.py β βββ feature_engineering.py β βββ anomaly_detection.py β βββ model_utils.py β βββ .gitignore βββ README.md βββ requirement.txt
The project uses building electricity consumption data combined with building metadata and weather information.
The selected building is Hog_other_Tobias, located at the Hog site.
The final cleaned dataset contains:
17,544 observations
15 features
Timestamp information
Electricity consumption
Weather variables
Calendar/time features
After creating lag and rolling features, 17,376 observations were available for model training and evaluation.
The dataset was divided chronologically to preserve the time-series structure.
Training Set 13,900 samples
From: 2016-01-08 00:00:00
To: 2017-08-09 03:00:00
Testing Set 3,476 samples
From: 2017-08-09 04:00:00
To: 2017-12-31 23:00:00
A chronological split was used instead of random splitting to avoid using future information when predicting past observations.
Historical energy consumption is the strongest predictor of future consumption.
The previous 24-hour consumption (lag_24h) is the most important feature.
Hourly consumption follows clear time-of-day patterns.
Weekday consumption is slightly higher than weekend consumption.
Temperature variables show a noticeable relationship with energy consumption.
HistGradientBoosting achieved the best forecasting performance.
Prediction errors can be used to identify potentially unusual consumption periods.
The dashboard provides an interactive way to monitor energy demand and unusual patterns.
Possible future improvements include:
Real-time energy data integration
Multi-building forecasting
Advanced models such as XGBoost, LightGBM, or LSTM
Automated alert notifications for anomalies
Energy cost prediction
Carbon-emission estimation
Building-to-building benchmarking
Cloud deployment
Automated model retraining
More advanced explainable AI techniques
The main objective of EnerSense AI is to demonstrate how machine learning and data analytics can be used to:
Forecast building energy consumption
Understand energy usage patterns
Detect unusual consumption
Analyze weather and temporal factors
Support data-driven building energy management
Ashfiya
Aspiring Data Analyst | Python | SQL | Data Analytics | Machine Learning
End-to-end data analytics project
Time-series energy forecasting
Feature engineering
Machine learning model comparison
Anomaly detection
Interactive Streamlit dashboard
Data visualization
GitHub-ready project structure
This project is developed for educational and portfolio purposes. The predictions and anomaly detection results are based on the available dataset and should not be considered a substitute for professional building-energy audits or operational decisions.
If you find this project useful, consider giving the repository a β on GitHub.






