Downloads · 30 days
0
Vikaash17/Energy-Consumption-Anomaly-Detection
Energy-Consumption-Anomaly-Detection is a tabular classification model from Vikaash17. Use it for the tabular classification task on the model card, and read the license before you ship it in a product. It is set up for sklearn. The card lists the license as apache-2.0.
A Random Forest classifier for detecting anomalies in hourly energy meter readings across 200 commercial buildings, with per-building MinMax scaling and engineered temporal/statistical features.
Downloads · 30 days
0
Access
Public
Updated Aug 21, 2026
Repo size
470 MB
Likes
0
Public
Click a slice to open those files.
.skops236 MB · 100%
From the Hugging Face model README
A Random Forest classifier for detecting anomalies in hourly energy meter readings across 200 commercial buildings, with per-building MinMax scaling and engineered temporal/statistical features.
This model classifies hourly energy meter readings as Normal or Anomaly, enabling automated monitoring of large-scale building infrastructure without manual review of individual meter logs. It was selected after comparing five candidate models (Transformer Autoencoder, LSTM Autoencoder, XGBoost, LightGBM, Random Forest) and achieved the best precision/recall balance on a highly imbalanced dataset (98.5% normal vs. 1.5% anomaly).
Note: The trained model file (~222MB) is hosted here on Hugging Face rather than GitHub due to GitHub's file size limits. The Flask web application code, preprocessing pipeline, and dashboard remain in the GitHub repository.
Not intended for buildings outside the original 200-building training set without validation, non-hourly reading frequencies, or meter types substantially different from those in training. Not designed as a general-purpose anomaly detector for non-energy tabular data.
Users should validate performance on new buildings before production use, and treat predictions for buildings with historically lower F1 scores (e.g., Building 240) with additional scrutiny.
The model is serialized using skops, a secure format for sharing scikit-learn models that avoids the arbitrary code execution risks associated with pickle.
import pandas as pd
from skops.io import load
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(
repo_id="Vikaash17/Energy-Consumption-Anomaly-Detection",
filename="model.skops" # replace with your actual filename in the repo
)
model = load(model_path)
# Input requires 15 engineered features (see Training Data section)
# X = preprocessed_dataframe[feature_columns]
predictions = model.predict_proba(X)[:, 1]
anomaly_flag = predictions >= 0.20 # optimal threshold
Hourly energy meter readings from 200 commercial buildings over a full year (8,736 hours), ~1.4M+ records. Raw inputs: building_id, timestamp, meter_reading. Anomaly labels were generated via statistical deviation analysis. Dataset is not publicly available.
15 engineered features computed from the 3 raw inputs, requiring a minimum of 49 prior readings per building:
| Feature | Description |
|---|---|
meter_reading_scaled | Per-building MinMax scaled reading (scaler fit on normal data only) |
lag_1, lag_2, lag_3 | Readings 1/2/3 hours prior |
lag_24, lag_48 | Readings 24/48 hours prior |
rolling_mean_24, rolling_std_24, rolling_max_24 | 24-hour rolling statistics |
hour_sin, hour_cos | Cyclical hour-of-day encoding |
day_sin, day_cos | Cyclical day-of-month encoding |
month_sin, month_cos | Cyclical month encoding |
| Model | Precision | Recall | F1 (Anomaly) | Macro F1 |
|---|---|---|---|---|
| Transformer Autoencoder | 0.30 | 0.02 | 0.04 | 0.50 |
| LSTM Autoencoder | 0.19 | 0.28 | 0.23 | 0.58 |
| XGBoost | 0.51 | 0.89 | 0.65 | 0.76 |
| LightGBM | 0.49 | 0.90 | 0.64 | 0.75 |
| Random Forest (this model) | 0.81 | 0.89 | 0.85 | 0.92 |
| Threshold | Precision | Recall | F1 Score |
|---|---|---|---|
| 0.50 (default) | 0.97 | 0.68 | 0.80 |
| 0.40 | 0.96 | 0.72 | 0.82 |
| 0.30 | 0.94 | 0.76 | 0.84 |
| 0.20 (optimal) | 0.81 | 0.89 | 0.85 |
| 0.15 | 0.84 | 0.83 | 0.83 |
| Metric | Value |
|---|---|
| Mean F1 across 200 buildings | 0.96 |
| Buildings with F1 = 1.00 | 30+ |
| Buildings with F1 ≥ 0.90 | ~185 / 200 |
| Buildings with F1 < 0.85 | 10 / 200 |
| Minimum F1 (Building 240) | 0.76 |
Random Forest outperformed all other candidates, including deep learning approaches, largely due to the tabular nature of the feature set and severe class imbalance, which disadvantaged the autoencoder-based models. XGBoost and LightGBM had strong recall but weaker precision (more false alarms). Threshold tuning improved anomaly recall from 0.68 to 0.89 vs. the default 0.50 threshold.
Random Forest Classifier (scikit-learn) with tuned decision threshold (0.20), trained for binary anomaly classification on engineered tabular features.
Vikaash17 — via Hugging Face profile or GitHub repository issues.