license: mit
tags:
- regression
- scikit-learn
- linear-regression
- electricity-consumption
- tabular
library_name: scikit-learn
Electricity Bill Regression Model
A Linear Regression model that predicts a household's daily electricity consumption (kWh) from appliance usage hours. Used to power a "what-if" electricity bill calculator, deployed as a Streamlit app.
Model Description
- Model type: Linear Regression (scikit-learn, OLS)
- Task: Regression - predicts
Daily_kWhfrom 13 appliance usage-hour features - Preprocessing: Features are scaled using
StandardScalerbefore being passed to the model - Files included:
linear_regression_model.pkl- the trained regression modelscaler.pkl- the fitted StandardScaler (must be used to transform any new input before prediction)feature_columns.pkl- the exact list and order of input feature names the model expects
Intended Use
Given a household's typical daily appliance usage hours, this model estimates daily electricity consumption. That estimate can then be scaled to a full month and passed through a fixed slab-based electricity tariff formula (LT Commercial tariff) to estimate a monthly bill. The tariff calculation itself is NOT part of this model, it is applied separately after prediction, since it is a fixed government rate structure, not a learned relationship.
Input Features
The model expects 13 numeric features, in this exact order (see feature_columns.pkl for the authoritative list):
AC_Hours, Fridge_Hours, Heater_Hours, Fan_Hours, Light_Hours, NightLamp_Hours, LEDBulb_Hours, TV_Hours, WashingMachine_Hours, Chimney_Hours, Mixer_Hours, Grinder_Hours, InductionStove_Hours
Each represents hours of use per day (0-24) for that appliance.
Training Data
Trained on a synthetically generated dataset simulating 9 years (2017-2025) of daily electricity usage for a single household, ~3,269 rows after cleaning (missing values dropped, invalid negative values removed, outliers removed using the IQR method).
Note: Daily_kWh in the training data was generated using a deterministic formula (hours x fixed appliance wattage), with no added noise. This means the model achieves a very high (near 100%) R-Squared score on this dataset, which reflects the noise-free nature of the training data rather than an unusually strong real-world model. On genuine smart-meter data with natural variance, performance would be expected to be lower.
How to Use
This model predicts only daily electricity consumption (kWh). It does not predict the monthly bill directly, since bill calculation depends on a fixed government tariff formula (slab-based rates), not something a model should learn. The example below shows the complete pipeline: get the daily prediction from the model, scale it to a full month, then apply the tariff formula separately to get the estimated bill.
from huggingface_hub import hf_hub_download
import joblib
import pandas as pd
import calendar
REPO_ID = "SelvaMech/electricity-bill-regression"
model = joblib.load(hf_hub_download(repo_id=REPO_ID, filename="linear_regression_model.pkl"))
scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename="scaler.pkl"))
feature_columns = joblib.load(hf_hub_download(repo_id=REPO_ID, filename="feature_columns.pkl"))
# user_values must be in the same order as feature_columns
user_values = pd.DataFrame([[5, 24, 1, 8, 5, 8, 6, 3, 0.5, 0.5, 0.1, 0.1, 1]], columns=feature_columns)
scaled_input = scaler.transform(user_values)
predicted_daily_kwh = model.predict(scaled_input)[0]
# Scale to a full month (example: August 2026)
days = calendar.monthrange(2026, 8)[1]
monthly_units = predicted_daily_kwh * days
# LT Commercial slab tariff - deterministic formula, not part of the model
if monthly_units <= 100:
bill = monthly_units * 5.5 + 120
elif monthly_units <= 250:
bill = (100 * 5.5) + (monthly_units - 100) * 6.5 + 120
else:
bill = (100 * 5.5) + (150 * 6.5) + (monthly_units - 250) * 7.2 + 120
print(f"Predicted Daily kWh : {predicted_daily_kwh:.2f}")
print(f"Predicted Monthly Units : {monthly_units:.2f}")
print(f"Estimated Bill : Rs {bill:.2f}")
Limitations
- Trained on synthetic, single-household data, not real smart-meter readings.
- Assumes a fixed electricity tariff rate across all years; real tariffs are revised periodically.
- Does not account for appliance efficiency (star ratings) or seasonal usage patterns as separate model inputs.
- Should not be used as a substitute for an actual utility bill; it is an educational estimation tool.
Live Demo
Try the deployed calculator here: [(https://ebbillpredictionsampledeployment-bpne9za7xb7p2kkp7eejza.streamlit.app)]
Author
Built by Selvanaayagam Ravy as part of a personal Data Analytics/AI portfolio project. Full training code and dataset details: [https://github.com/selvanaayagam-tech/EB_billprediction_sample_deployment]