Skip to content

SkullKrak7/Predictive-Maintenance-Pipeline

Repository files navigation

Predictive Maintenance Pipeline

A production-ready predictive maintenance system with ML-powered failure prediction, real-time monitoring dashboard, and REST API. Features an enhanced UI with comprehensive metrics, interpretations, and professional orange/amber alert theme.


Why this project

Forecast machine failures before they occur to minimize downtime and maintenance costs. Includes a modern web dashboard with real-time predictions, system metrics, and confidence scoring.


Key features

  • Three sensor inputs: Rotational speed (rpm), Torque (Nm), Tool wear (minutes)
  • ML Models: XGBoost/Random Forest with class imbalance handling via scale_pos_weight
  • Enhanced Dashboard:
    • Real-time failure probability predictions
    • System performance metrics (uptime, request count, P95 latency)
    • Confidence level interpretation
    • Alert-focused orange/amber color scheme
    • Responsive 3-column layout
    • API documentation
  • REST API with health checks and metrics endpoints
  • Docker containerized with automated model training during build

Quick start

Docker (Recommended)

docker build -t predictive-maintenance .
docker run -d -p 5001:5000 predictive-maintenance

Open http://localhost:5001 for the dashboard.

Local

Requires Python 3.11+ and pydantic.

python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

# Train model
python train_model.py

# Start server
python flask_app.py

API Endpoints

Health Check

GET /health
Response: {"status": "ok"}

Metrics

GET /metrics
Response: {
  "uptime_s": 123.45,
  "requests_total": 42,
  "latency_p95_ms": 12.34
}

Prediction

POST /predict
Content-Type: application/json

{
  "rotational_speed": 1500,
  "torque": 30,
  "tool_wear": 5
}

Response: {
  "failure_probability": 0.234,
  "predicted_label": 0,
  "threshold": 0.5
}

Dashboard Features

Input Parameters

  • Rotational Speed: 1100-3000 rpm
  • Torque: 0-100 Nm
  • Tool Wear: 0-300 minutes
  • Decision Threshold: 0.0-1.0 (default: 0.5)

Results Display

  • Prediction Badge: Visual alert (✅ Normal / ⚠️ Failure Predicted)
  • Failure Probability: Percentage with confidence level
  • System Metrics: Real-time performance monitoring
  • Interpretation: Actionable recommendations based on prediction
  • Model Info: Algorithm details and use case explanation

Project structure

.
├─ templates/
│   └─ index.html          # Enhanced dashboard UI
├─ outputs/                # Model artifacts
├─ tests/
│   └─ test_api.py
├─ flask_app.py            # Flask server with metrics
├─ train_model.py          # Model training pipeline
├─ models.py               # Pydantic validation
├─ predictive_maintenance.csv
├─ requirements.txt        # Includes pydantic
├─ Dockerfile
└─ .github/workflows/ci.yml

Model Details

Features: Rotational speed, torque, and tool wear are key indicators of equipment health

Algorithm: Ensemble methods (Random Forest / XGBoost) trained on industrial sensor data with StandardScaler normalization

Training Pipeline:

  1. Drop IDs and handle missing values
  2. One-hot encode equipment type
  3. Scale numeric features
  4. Handle class imbalance with scale_pos_weight
  5. Save model, scaler, and feature names to model.pkl

Artifacts:

  • model.pkl - Trained model with scaler and feature names
  • outputs/corr_heatmap.png - Feature correlation analysis
  • outputs/feature_importance_rf.png - Feature importance plot
  • outputs/metrics.json - Model performance metrics

UI Design

Color Scheme: Orange/amber alert theme (industry standard for maintenance systems)

  • Background: Dark brown/stone (#0f0a05)
  • Primary: Orange gradient (#f59e0b to #ef4444)
  • Accents: Warm amber tones
  • Purpose: Conveys urgency and monitoring focus

Layout: Full-width responsive design with 3-column grid for optimal horizontal space usage


Testing and CI

# Run all quality checks
ruff check . && black --check . && pytest -q

# Run tests only
python -m pytest -q

CI Pipeline (GitHub Actions):

  1. Install dependencies
  2. Train model
  3. Lint with ruff
  4. Format check with black
  5. Run pytest
  6. Build Docker image

Performance Monitoring

The dashboard tracks:

  • Uptime: Server runtime in seconds
  • Total Requests: Cumulative prediction count
  • P95 Latency: 95th percentile response time in milliseconds

Metrics are displayed in real-time on the dashboard and available via /metrics endpoint.


Licence

MIT Licence. See LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors