This repository contains a 4-layer IoT anomaly detection and predictive maintenance pipeline
trained on real industrial sensor data collected via MQTT protocol.
The system predicts machine health degradation and detects anomalies from IoT sensor readings
in real-time, designed for integration with Oracle AI Agents and MQTT brokers.
Models in This Repository
File
Model Type
Purpose
rf_forecast_model.joblib
Random Forest Regressor (300 trees)
Predicts future machine health score (0–100)
scaler.joblib
StandardScaler
Feature normalization (must be applied before prediction)
Pipeline Architecture
Layer 1: Isolation Forest → Anomaly Detection & Scoring
Layer 2: Random Forest Regressor → Machine Health Score (0–100)
Layer 3: Rule-based Engine → Root Cause Explanation
Layer 4: RF Forecasting Model → Future Health Prediction + Time-to-Critical
Input Features
The forecasting model (rf_forecast_model.joblib) requires these 8 features, in exact order:
#
Feature
Description
Unit
1
temp_celsius
Temperature reading
°C
2
high_temp_duration
Consecutive steps above 75°C
steps
3
thermal_stress_code
0=NORMAL, 1=HIGH, 2=CRITICAL
categorical
4
degradation_rate
Rate of health degradation (1–8x)
multiplier
5
health_score
Current machine health
0–100
6
health_delta
Change in health since last reading
points
7
light_value
Ambient light sensor reading
lux
8
anomaly_score
Isolation Forest anomaly score
float
How to Use
python
1import joblib
2import numpy as np
3from huggingface_hub import hf_hub_download
45# Download and load models directly from Hugging Face6model_path = hf_hub_download("HarshaMuralidharan04/iot-anomaly-detection","rf_forecast_model.joblib")7scaler_path = hf_hub_download("HarshaMuralidharan04/iot-anomaly-detection","scaler.joblib")89model = joblib.load(model_path)10scaler = joblib.load(scaler_path)1112# Example: One machine reading13features = np.array([[1472.5,# temp_celsius153,# high_temp_duration160,# thermal_stress_code (NORMAL)171.0,# degradation_rate1885.2,# health_score19-0.5,# health_delta20210.0,# light_value210.12# anomaly_score22]])2324# IMPORTANT: Always scale before predicting25features_scaled = scaler.transform(features)26predicted_future_health = model.predict(features_scaled)27print(f"Predicted health in 5 steps: {predicted_future_health[0]:.1f}/100")
Training Data
Source: Real MQTT sensor data from industrial IoT devices
Split: 80% training / 20% test (time-aware split — no future data leakage)
Performance
Metric
Forecasting Model
MAE (Mean Absolute Error)
< 3.0 health points
R² Score
> 0.95
Training samples
~2,800
Test samples
~700
Intended Use
✅ Intended for:
Industrial equipment health monitoring
Predictive maintenance scheduling
Real-time anomaly alerting via MQTT / Oracle AI Agents
⛔ Not intended for:
Medical devices or safety-critical systems without additional validation
Consumer electronics (trained on industrial sensor ranges)
Authors
HarshaMuralidharan04 — IoT Anomaly Detection Project
Developed as part of an Oracle AI Agent + MQTT integration pipeline for industrial predictive maintenance.
License
MIT License — Free to use, modify, and distribute with attribution.