Instructions to use Vikaash17/Energy-Consumption-Anomaly-Detection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Vikaash17/Energy-Consumption-Anomaly-Detection with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Vikaash17/Energy-Consumption-Anomaly-Detection", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Model Card for energy-consumption-anomaly-detection
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.
Model Details
Model Description
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).
- Developed by: Vikaash17
- Model type: Random Forest Classifier (tabular, binary classification)
- Language(s): N/A (tabular numeric data)
- License: Apache 2.0
- Trained from scratch: Yes (not fine-tuned from a pretrained model)
Model Sources
- GitHub Repository: https://github.com/Vikaash-17/Energy_Consumption_Anomaly_Detection
- Hugging Face Repository: https://huggingface.co/Vikaash17/Energy-Consumption-Anomaly-Detection
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.
Uses
Direct Use
Bulk anomaly detection on hourly energy meter readings via CSV upload, for facility managers and energy analysts monitoring multiple buildings. Designed to work with the accompanying Flask web application for interactive prediction and visualization.
Out-of-Scope Use
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.
Bias, Risks, and Limitations
- Trained on 200 specific buildings; generalization to new buildings relies on a global fallback scaler and has not been extensively validated.
- Severe class imbalance (1.5% anomalies) means the model may still under-detect rare/novel anomaly patterns not represented in training data.
- Per-building performance varies (F1 range: 0.76–1.00 across buildings) — lower-performing buildings should be monitored more closely.
Recommendations
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.
How to Get Started with the Model
⚠️ Note: This model is serialized using Python's
picklemodule. Only load pickle files from sources you trust, as they can execute arbitrary code during deserialization.
import pickle
import pandas as pd
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(
repo_id="Vikaash17/Energy-Consumption-Anomaly-Detection",
filename="model.pkl" # replace with your actual filename in the repo
)
with open(model_path, "rb") as f:
model = pickle.load(f)
# 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
Training Details
Training Data
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.
Feature Engineering
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 |
Training Procedure
- Train/test split: 80% / 20%
- Class-imbalance-aware evaluation (98.5% normal / 1.5% anomaly)
- Detection threshold tuned via precision-recall curve analysis (optimal: 0.20, vs. default 0.50)
Evaluation
Model Comparison
| 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 |
Global Classification Report (Threshold = 0.20)
| Class | Precision | Recall | F1 Score | Support |
|---|---|---|---|---|
| Normal (0) | 1.00 | 1.00 | 1.00 | 341,304 |
| Anomaly (1) | 0.81 | 0.89 | 0.85 | 6,675 |
| Accuracy | 0.99 | 347,979 | ||
| Macro Avg | 0.90 | 0.94 | 0.92 | 347,979 |
| Weighted Avg | 0.99 | 0.99 | 0.99 | 347,979 |
Threshold Optimization
| 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 |
Per-Building Performance
| 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 |
Summary
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.
Technical Specifications
Model Architecture and Objective
Random Forest Classifier (scikit-learn) with tuned decision threshold (0.20), trained for binary anomaly classification on engineered tabular features.
Compute Infrastructure
Software
- Python 3.x
- scikit-learn
- Pandas, NumPy
- Pickle (model serialization)
- Flask (deployment/web app)
Model Card Contact
Vikaash17 — via Hugging Face profile or GitHub repository issues.
- Downloads last month
- -
Evaluation results
- F1 (Anomaly Class)self-reported0.850
- Macro F1self-reported0.920
- Precision (Anomaly Class)self-reported0.810
- Recall (Anomaly Class)self-reported0.890