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.
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.
- 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
docker build -t predictive-maintenance .
docker run -d -p 5001:5000 predictive-maintenanceOpen http://localhost:5001 for the dashboard.
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.pyGET /health
Response: {"status": "ok"}GET /metrics
Response: {
"uptime_s": 123.45,
"requests_total": 42,
"latency_p95_ms": 12.34
}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
}- Rotational Speed: 1100-3000 rpm
- Torque: 0-100 Nm
- Tool Wear: 0-300 minutes
- Decision Threshold: 0.0-1.0 (default: 0.5)
- 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
.
├─ 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
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:
- Drop IDs and handle missing values
- One-hot encode equipment type
- Scale numeric features
- Handle class imbalance with
scale_pos_weight - Save model, scaler, and feature names to
model.pkl
Artifacts:
model.pkl- Trained model with scaler and feature namesoutputs/corr_heatmap.png- Feature correlation analysisoutputs/feature_importance_rf.png- Feature importance plotoutputs/metrics.json- Model performance metrics
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
# Run all quality checks
ruff check . && black --check . && pytest -q
# Run tests only
python -m pytest -qCI Pipeline (GitHub Actions):
- Install dependencies
- Train model
- Lint with ruff
- Format check with black
- Run pytest
- Build Docker image
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.
MIT Licence. See LICENSE.