Skip to content

Dhanush-1213/predictive-maintenance-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Predictive Maintenance System

An industrial IoT application that uses machine learning to predict equipment failures before they happen


Python FastAPI Uvicorn scikit-learn Pandas NumPy

React Vite React Router Recharts Axios


Screenshots

Dashboard Machine Alerts
Dashboard 1 Dashboard 3
Sensor Chart & Table Upload Data Model Metrics
Dashboard 2 Upload Metrics
Confusion Matrix
Confusion Matrix

Overview

Unplanned machine downtime is one of the costliest problems in industrial operations. This system uses a trained Random Forest classifier on the AI4I 2020 Predictive Maintenance Dataset to analyze real-time sensor readings and predict the probability of machine failure before it happens.

The backend exposes a FastAPI REST API for both single and batch predictions. The frontend is a React + Vite dashboard with live health status cards, sensor charts, alert panels, and a CSV batch upload tool.


Features

  • Real-time Failure Prediction — Submit live sensor readings and get instant failure probability, risk score, and health status
  • Batch CSV Upload — Upload a CSV file of sensor readings and get predictions for every row at once
  • Health Status Classification — Each machine is labelled Healthy, Warning, or Critical based on risk score thresholds
  • Actionable Recommendations — Rule-based engine surfaces specific maintenance guidance (e.g. "Inspect cooling system and consider tool replacement")
  • Interactive Sensor Charts — Recharts-powered visualizations of torque, temperature, tool wear, and rotational speed across machines
  • Model Metrics Dashboard — Accuracy, Precision, Recall, F1 Score, ROC-AUC, feature importances, and confusion matrix — all served live from the model bundle
  • Responsive UI — Clean React dashboard with gradient layout, card-based health indicators, and alert panels

Tech Stack

Backend

Technology Badge Purpose
Python 3.10+ Python Core language
FastAPI FastAPI REST API framework
Uvicorn Uvicorn ASGI server
scikit-learn scikit-learn Random Forest classifier
Pandas Pandas Data processing & CSV parsing
NumPy NumPy Numerical operations
joblib joblib Model serialization (.pkl)
Matplotlib Matplotlib Confusion matrix plot generation
Pydantic Pydantic Request schema validation
python-multipart multipart CSV file upload handling

Frontend

Technology Badge Purpose
React 19 React UI framework
Vite 8 Vite Build tool & dev server
React Router DOM v7 React Router Client-side routing
Recharts Recharts Sensor data bar/line charts
Axios Axios HTTP client for API calls

Project Structure

predictive-maintenance-system/
│
├── backend/
│   ├── app/
│   │   ├── main.py              # FastAPI app & all route definitions
│   │   ├── schemas.py           # Pydantic input schema (SensorDataInput)
│   │   ├── ml/
│   │   │   ├── predictor.py     # Inference, risk scoring & recommendation engine
│   │   │   └── model.pkl        # Pre-trained RF bundle (model + metrics + features)
│   │   └── static/
│   │       └── confusion_matrix.png
│   ├── train_model.py           # Training, evaluation & artifact generation script
│   └── requirements.txt
│
├── frontend/
│   ├── index.html
│   ├── vite.config.js
│   ├── package.json
│   └── src/
│       ├── App.jsx
│       ├── main.jsx
│       ├── pages/
│       │   ├── Dashboard.jsx    # Main health monitoring view
│       │   ├── UploadData.jsx   # Batch CSV prediction page
│       │   └── Metrics.jsx      # Model performance & feature importance
│       ├── components/
│       │   ├── Layout.jsx       # App shell & navigation bar
│       │   ├── HealthCard.jsx   # Summary stat cards
│       │   ├── AlertCard.jsx    # Warning & Critical alert items
│       │   ├── MachineTable.jsx # Full predictions table
│       │   └── SensorChart.jsx  # Recharts sensor visualization
│       └── services/
│           └── api.js           # Axios base URL configuration
│
├── data/
│   └── ai4i2020.csv             # UCI training dataset (10,000 rows)
│
└── screenshots/

Machine Learning Model

Detail Value
Algorithm Random Forest Classifier
Estimators 200 trees
Max Depth 10
Class Weights Balanced (handles ~3.4% positive rate)
Train / Test Split 80% / 20% (stratified)
Features Air temp, Process temp, Rotational speed, Torque, Tool wear
Target Binary Machine failure label

Risk Score Thresholds

Risk Score Status Action
≤ 30 Healthy Continue monitoring
31 – 70 ⚠️ Warning Schedule inspection
> 70 🔴 Critical Immediate action required

Rule-Based Recommendation Engine

Sensor Condition Recommendation
Process temp > 310 K and Tool wear > 200 min Inspect cooling system and consider tool replacement
Torque > 50 Nm and Rotational speed < 1400 rpm Check motor load and shaft alignment
Air temp > 305 K and Torque > 55 Nm Inspect overheating and vibration-related components
Default No immediate action required. Continue monitoring

Getting Started

Prerequisites

Python Node.js npm


1. Clone the Repository

git clone https://github.com/Dhanush-1213/predictive-maintenance-system.git
cd predictive-maintenance-system

2. Backend Setup

cd backend

# Create and activate virtual environment (recommended)
python -m venv venv
source venv/bin/activate          # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# (Optional) Retrain the model — a pre-trained model.pkl is already included
python train_model.py

# Start the API server
uvicorn app.main:app --reload

APIhttp://127.0.0.1:8000
Swagger Docshttp://127.0.0.1:8000/docs


3. Frontend Setup

Open a new terminal:

cd frontend
npm install
npm run dev

Apphttp://localhost:5173

Make sure the backend server is running before launching the frontend.


📖 Usage

Dashboard

Click "Run Sample Predictions" to run the model against 4 built-in machines with varied sensor profiles:

  • View health summary cards (Total / Healthy / Warning / Critical)
  • Inspect per-sensor readings in an interactive bar chart
  • Review real-time alerts for Warning and Critical machines
  • Browse the full prediction table with risk scores and recommendations

Upload Data (Batch Prediction)

Navigate to Upload Data to submit a CSV with multiple sensor readings at once.

Required CSV columns:

Column Name Alternate (auto-renamed) Description
Air temperature [K] Air_temperature_K Ambient temperature in Kelvin
Process temperature [K] Process_temperature_K Process temperature in Kelvin
Rotational speed [rpm] Rotational_speed_rpm Spindle speed
Torque [Nm] Torque_Nm Applied torque
Tool wear [min] Tool_wear_min Cumulative tool wear in minutes

The API accepts both bracket-style and underscore-style column names — export directly from any SCADA or historian system.

Model Metrics

Navigate to Metrics to view live model performance fetched from the model bundle: Accuracy, Precision, Recall, F1 Score, ROC-AUC, feature importance rankings, and the confusion matrix.


API Reference

GET /

Health check. Returns { "message": "Predictive Maintenance API is running" }.


GET /metrics

Returns model evaluation metrics and feature importances directly from the saved model bundle.


POST /predict

Single machine prediction.

Request:

{
  "Air_temperature_K": 300.0,
  "Process_temperature_K": 310.5,
  "Rotational_speed_rpm": 1500,
  "Torque_Nm": 45.0,
  "Tool_wear_min": 120
}

Response:

{
  "failure_prediction": 0,
  "failure_probability": 0.0821,
  "risk_score": 8.21,
  "health_status": "Healthy",
  "recommendation": "No immediate action required. Continue monitoring."
}

POST /predict-batch

Batch prediction from a CSV file upload.

Request: multipart/form-data with a .csv file in a field named file

Response:

{
  "total_rows": 100,
  "predictions": [
    {
      "row_id": 0,
      "failure_prediction": 1,
      "failure_probability": 0.8342,
      "risk_score": 83.42,
      "health_status": "Critical",
      "recommendation": "Inspect cooling system and consider tool replacement."
    }
  ]
}

Dataset

AI4I 2020 Predictive Maintenance Dataset — UCI Machine Learning Repository

  • 10,000 data points simulating industrial milling machine sensor behavior
  • 5 features used for training after dropping metadata and sub-failure-type columns
  • ~3.4% positive (failure) rate — handled via class_weight="balanced"

Matzka, S. (2020). Explainable Artificial Intelligence for Predictive Maintenance Applications. IEEE AIKE.


Future Improvements

  • WebSocket support for live streaming sensor data
  • Time-series anomaly detection model (LSTM / Isolation Forest)
  • Docker + Docker Compose for one-command deployment
  • Authentication & multi-user support
  • Historical prediction logging with a database backend
  • Email / Slack alert notifications for Critical machines
  • Export batch prediction results as CSV

Author

Dhanush K
PES University | CSE (AIML)
LinkedIn: @Dhanush K


⭐ If you found this project helpful, give it a star!

Built with ⚙️ FastAPI · ⚛️ React · 🌲 scikit-learn

About

Predictive maintenance system that analyzes industrial sensor data to estimate machine failure risk and visualize equipment health through a FastAPI and React dashboard.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors