Skip to content

Vishnu3022/IoT_PredictiveMaintenance-Engine

Repository files navigation

IoT Predictive Maintenance System

An end-to-end Machine Learning pipeline designed for Predictive Maintenance of IoT sensor systems. It generates robust time-series features, handles extreme class imbalances (<1% failure rate), incorporates SHAP-based local explainability, and deploys the final XGBoost model via a high-performance Flask API.

Project Structure

  • feature_engineering.py: Generates foundational time-series signals including Rolling Means, Exponential Moving Averages (EMA), and standard deviations over 1h, 6h, and 12h windows. Serializes the prepared data into engineered_features.joblib.
  • model_selection.py: Handles extreme class imbalance using imblearn SMOTE and scale_pos_weight. Maximizes Precision-Recall AUC (PR-AUC) rather than pure accuracy to avoid false alarms. Employs Optuna to aggressively search for the best XGBoost hyperparameters, saving the final champion model to xgboost_production_model.joblib.
  • model_explainability.py: Provides both visual and analytical ML explainability. It isolates positive failure predictions from the model and draws SHAP (SHapley Additive exPlanations) Waterfall plots and Global summaries to inform the Maintenance Engineer exactly why a failure alert triggered.
  • api.py: A low-latency real-time inference Flask Server. Accepting JSON payload histories of sensor metrics, it calculates the rolling features dynamically in memory and evaluates them using the XGBoost production model within <50ms runtime, outputting real-time Risk indicators.
  • test_api_client.py: A helper automation script simulating the physical IoT network, sending payloads to test network round-trip latency against api.py.

Installation & Setup

Ensure you are using your target Python environment (e.g., Python 3.13) and install the entire dependency stack:

pip install pandas numpy scikit-learn xgboost optuna imbalanced-learn shap matplotlib flask requests joblib

Execution Pipeline

To correctly train the model from scratch and deploy the inference API, strictly follow this execution order:

  1. Feature Engineering:
    python feature_engineering.py
  2. Model Selection & Tuning:
    python model_selection.py
  3. Model Explainability (Optional): (Produces .png SHAP visualizations and terminal logic paths)
    python model_explainability.py
  4. Boot up Inference API:
    python api.py
  5. Test Latency / Network Simulation (Open in a new terminal):
    python test_api_client.py