Predictive Maintenance: Failure-Mode Classifier (XGBoost)
Predicts, from a single machine reading, whether a milling machine is healthy or heading towards one of four failure modes: tool wear, heat dissipation, power or overstrain. It was tuned with Optuna for macro-F1, tracked and registered with MLflow, explained per class with SHAP, and monitored for drift with Evidently.
Live demo: runs in the browser on the project page · Code and full pipeline: github.com/kritikesh28/predictive-maintenance-mlops
Model details
| Algorithm | XGBoost XGBClassifier (multi:softprob, 5 classes) |
| Tuning | Optuna TPE sampler, seed 42, 30 trials, objective = macro-F1 on validation |
| Best params | n_estimators 407 · max_depth 6 · learning_rate 0.0325 · min_child_weight 4.94 · subsample 0.836 · colsample_bytree 0.915 · gamma 1.63 · reg_alpha 3.6e-5 · reg_lambda 0.0092 |
| Imbalance handling | SMOTE (k_neighbors=3), applied to the training split only |
| Files | xgb_predmaint.joblib (scikit-learn API, xgboost 2.1.3), xgb_predmaint.json (native booster), config.json (feature spec) |
| Developed by | Kritikesh Rajpurohit |
| Licence | MIT (model and code) · training data CC BY 4.0 |
Inputs
Six raw readings, plus three values derived from them:
| Feature | Unit | Notes |
|---|---|---|
| Type | L / M / H | product quality variant, encoded H=0, L=1, M=2 |
| Air temperature | K | 295–305 |
| Process temperature | K | 305–315 |
| Rotational speed | rpm | 1000–2900 |
| Torque | Nm | 3–80 |
| Tool wear | min | 0–253 |
| Power_W | W | Torque × Rotational speed × 2π / 60 |
| Temp_diff | K | Process temperature − Air temperature |
Outputs
Probabilities for 0 No Failure · 1 TWF · 2 HDF · 3 PWF · 4 OSF.
How to use
import joblib, numpy as np, pandas as pd
from huggingface_hub import hf_hub_download
model = joblib.load(hf_hub_download("kritikesh28/predictive-maintenance-xgboost", "xgb_predmaint.joblib"))
df = pd.DataFrame([{"Type": "M", "Air temperature": 302.8, "Process temperature": 312.3,
"Rotational speed": 1262, "Torque": 70.5, "Tool wear": 234}])
df["Type_enc"] = df["Type"].map({"H": 0, "L": 1, "M": 2})
df["Power_W"] = df["Torque"] * df["Rotational speed"] * 2 * np.pi / 60
df["Temp_diff"] = df["Process temperature"] - df["Air temperature"]
X = df[["Type_enc", "Air temperature", "Process temperature", "Rotational speed",
"Torque", "Tool wear", "Power_W", "Temp_diff"]]
print(model.predict_proba(X).round(3)) # -> OSF (overstrain) with p = 0.928
A complete script is in inference.py.
Training data
Derived from the AI4I 2020 Predictive Maintenance Dataset (UCI Machine Learning Repository, CC BY 4.0; S. Matzka, 2020). It is a synthetic dataset that mirrors real milling-machine behaviour.
- Baseline (training and validation): 6,993 rows. Class mix: 96.70% No Failure, 0.43% TWF (30 rows), 1.09% HDF, 0.80% PWF, 0.99% OSF.
- Two post-deployment batches of 1,499 rows each, used for monitoring only: stable and heavy-load.
Evaluation
Stratified 80/20 split of the baseline (seed 42). The validation set is the real class mix and was never resampled.
| Metric | Baseline XGBoost | This model (tuned) |
|---|---|---|
| Macro-F1 (selection metric) | 0.748 | 0.767 |
| Weighted-F1 | 0.985 | 0.983 |
| Accuracy | 0.984 | 0.977 |
| F1 No Failure | 0.992 | 0.989 |
| F1 TWF | 0.133 | 0.069 |
| F1 HDF | 0.966 | 0.966 |
| F1 PWF | 0.880 | 0.917 |
| F1 OSF | 0.769 | 0.897 |
Compared against Random Forest (0.736), LightGBM (0.730) and Logistic Regression (0.531) on macro-F1. Accuracy is reported but not used to select a model: always predicting "healthy" would already score 96.7%.
Behaviour under distribution shift
| Production batch | Evidently drift | Macro-F1 | OSF F1 |
|---|---|---|---|
| Stable | none (0/5 features) | 0.742 | 0.813 |
| Heavy-load | 3/5 features (tool wear +38%, torque +12%, rpm −3%) | 0.532 | 0.626 |
Both batches pass schema validation. The heavy-load batch is valid but shifted, and the model degrades on it. Retraining with heavy-load data is recommended before using this model in heavy-load conditions.
Explainability
Mean |SHAP| per failure class on the baseline data:
| Class | Top driver | Runner-up |
|---|---|---|
| TWF | Tool wear (3.13) | Torque (0.39) |
| HDF | Temp_diff (2.70) | Rotational speed (1.97) |
| PWF | Power_W (3.24) | Tool wear (0.51) |
| OSF | Torque (1.90) | Tool wear (1.87) |
Intended use and limitations
Intended use: a portfolio and reference implementation of an explainable predictive maintenance classifier and its MLOps loop. It is meant for learning, prototyping and decision-support experiments.
Out of scope: safety-critical or autonomous shutdown decisions on real equipment without recalibration on plant data.
Limitations
- Tool-wear failure (TWF) is unreliable (F1 0.07). There are only 30 real training examples, and SMOTE cannot create real variety from them. Use a rule-based tool-life limit alongside the model.
- Trained on synthetic data. Value ranges and thresholds (for example the overstrain alert at
tool wear × torque > 10,000 min·Nm) must be re-derived for real machines. - Performance drops under heavy-load conditions (see above). Monitor input drift and retrain when Torque or Tool wear drift.
- Validation per-class F1 for the rarest classes rests on 6–15 examples each, so treat those numbers as indicative.
Bias and fairness: the model works on machine telemetry only. It uses no personal data and makes no decisions about people.
Citation
@inproceedings{matzka2020ai4i,
author = {Matzka, Stephan},
title = {Explainable Artificial Intelligence for Predictive Maintenance Applications},
booktitle = {2020 Third International Conference on Artificial Intelligence for Industries (AI4I)},
pages = {69--74},
year = {2020}
}
Author: Kritikesh Rajpurohit · GitHub · LinkedIn · Project page
Capstone project of the Applied AI and Agentic AI programme, IIIT Bangalore. Packaging, model card and demo designed with Claude.
- Downloads last month
- 23


