Skip to content

Lipranj14/Hourly_Energy_Consumption_Forecasting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Energy Consumption Forecasting

This repository contains an end-to-end Machine Learning project that predicts next-day household energy consumption. The project uses the Individual household electric power consumption subset from the UCI Machine Learning Repository.

Project Overview

The dataset contains over 2 million records (minute-resolution measurements gathered over almost 4 years) of electric power consumption in a household in Sceaux, France.

The goal of this project is to build a time-series forecasting model using Scikit-Learn and XGBoost regressors to predict the total energy usage (Global_active_power) for the next hour. This is achieved by creating rolling window features, finding lagged variables, and extracting meaningful date-time properties from the data.

image image

Technologies Used

  • Python 3.9+
  • Pandas & NumPy (Data processing and feature engineering)
  • Scikit-Learn & XGBoost (Machine Learning regressors)
  • Matplotlib & Seaborn (Exploratory Data Analysis)
  • Streamlit (Interactive Dashboard)
  • Joblib (Model Exportation)

Feature Engineering & EDA

The minute-level data is resampled to an hourly frequency, then we generate the following features:

  1. Datetime Properties: hour, day_of_week, month, and an is_weekend flag.
  2. Lag Features: Historical energy consumption (lag_1hour, lag_24hour).
  3. Rolling Statistics: 24-hour and 7-day moving averages (rolling_mean_24h and rolling_mean_7day).

Setup and Usage

1. Environment Setup

Create a virtual environment and install the required dependencies:

python -m venv venv
# On Windows
venv\Scripts\activate.bat
# On macOS/Linux
source venv/bin/activate

pip install -r requirements.txt

2. Data Pipeline & EDA

Run the data pipeline script. This will download the dataset, parse the 2 million datetimes, resample to hourly frequency, engineer features, and generate Exploratory Data Analysis (EDA) plots in the results/ folder.

python data_pipeline.py

3. Model Training & Evaluation

Run the modeling training script. This script performs a temporal train-test split, trains a Naive Baseline, Linear Regression, Random Forest, and XGBoost regressor, then saves the best-performing model to models/best_model.joblib.

python train_evaluate.py

4. Interactive Dashboard

Run the Streamlit application to visually explore the forecasted predictions vs. the actual test data.

streamlit run app.py

Results & Insights

Models are evaluated on Mean Absolute Error (MAE), Root Mean Squared Error (RMSE), and R² Score.

  • XGBoost achieved the strongest performance with an R² of ~0.61 and an MAE of ~0.31 kW on the held-out test set, capturing the complex non-linear consumption patterns.
  • Naive Baseline: Predicting next hour's usage using the previous hour's usage yielded an R² of -0.17, proving that the trained models are successfully extracting forward-looking patterns.
  • The most important predictive features are lag_1hour and hour of the day.
  • Plots comparing actual vs. predicted values, alongside feature importance distributions, are automatically saved to the results/ folder upon running the training script.

About

Time-series forecasting using XGBoost to predict hourly energy consumption from 2M+ rows of data. Features temporal feature engineering and a Streamlit dashboard.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages