Predictive Maintenance: Predicting Machine Failure from Sensor Data with Python

This updated predictive-maintenance tutorial uses the 10,000-row AI4I 2020 benchmark to predict whether a machine fails. Failures account for only 3.4% of rows, so average precision and a prevalence baseline are more informative than accuracy alone.

Leakage-safe features and pipeline
The model excludes identifiers, Failure Type, Target, and Machine failure from its features. Keeping failure-derived columns would reveal the answer. The remaining sensor values are standardized and machine type is one-hot encoded inside a training-only pipeline.
model = Pipeline([
('preprocessor', preprocessor),
('classifier', LogisticRegression(
class_weight='balanced', max_iter=2000, random_state=42
)),
])
Verified holdout results
On the stratified holdout, balanced accuracy was 0.990, F1 was 0.990, ROC AUC was 0.982, and average precision was 0.981. The prevalence-only baseline average precision was 0.034.


Permutation importance
The strongest holdout permutation feature was PWF, measured by decrease in average precision. Correlated sensors can divide importance, and the ranking does not prove a failure mechanism.

Limitations
AI4I is synthetic. These results do not establish performance on a production line, another machine family, or a future operating regime. The random holdout does not test drift or maintenance interventions. Balanced weights and a 0.5 threshold create one false-alarm trade-off; deployment needs cost-based threshold selection, temporal validation, probability calibration, and monitoring.




3 Commentsarchived from the original site