Predictive Maintenance ML Pipeline

Predictive Maintenance ML Pipeline

← Back to projects

Context: Independent Machine Learning Project · 2026
Focus: Imbalanced classification · Model evaluation · Decision thresholds · Reproducible ML engineering

I built an end-to-end machine-learning workflow for predicting industrial equipment failures using the AI4I 2020 Predictive Maintenance Dataset.

The project goes beyond fitting a classifier. It treats predictive maintenance as an imbalanced decision problem: validating the data, engineering physically meaningful features, comparing multiple model families under stratified cross-validation, selecting thresholds without using the test set, estimating uncertainty, and analysing where the final model succeeds and fails.

View the full analysis notebook →
View the source on GitHub →

Project snapshot

MetricResult
Dataset10,000 equipment observations
Models compared8 classification approaches
Final modelTuned Random Forest
Cross-validated Average Precision0.8937
Held-out test Average Precision0.876
Test precision0.947
Test recall0.794
Test F1-score0.864
Correctly detected failures54 / 68
False alarms3
Selected operating threshold0.575
Bootstrap AP 95% CI0.798–0.942

The challenge

Machine failures are rare relative to normal operation, which makes conventional accuracy a poor primary objective. A model can achieve high accuracy while still missing the failures that matter.

The project therefore focused on four questions:

To keep the final evaluation defensible, the held-out test set was used only after model selection and threshold determination.

Data validation and leakage prevention

The workflow begins with explicit checks for missing values, duplicates, feature ranges, target integrity and class distribution.

Identifier columns such as UDI and Product ID are excluded from modelling. The five failure-mode indicators included in the dataset are also excluded from training because they directly encode the mechanism used to generate the target and would introduce target leakage.

The data is then split using a stratified train/test split, while model comparison and tuning are performed only on the training data using stratified cross-validation.

Domain-informed feature engineering

Three interaction features were derived from the original sensor measurements:

These features were chosen to reflect known failure mechanisms rather than adding arbitrary polynomial combinations.

An ablation analysis compares the raw feature set against the raw-plus-engineered representation before the final model is selected.

Model comparison and selection

I compared eight baseline and imbalance-aware classification approaches:

Average Precision was used as the primary model-selection metric because the positive class is rare and ranking likely failures is more informative than raw accuracy.

The tuned Random Forest achieved the strongest cross-validated result with 0.8937 Average Precision. Hyperparameter tuning provided only a marginal gain over the untuned Random Forest, an important result in itself: the performance came primarily from the modelling pipeline and feature representation rather than aggressive search.

Cross-validation comparison across candidate models

Threshold selection as a decision problem

The strongest probability model is not automatically the strongest decision system.

Instead of using the default 0.5 cutoff, I generated out-of-fold probabilities on the training set and selected a recall-constrained operating threshold before touching the held-out test data.

The selected threshold was 0.575.

I also evaluated an illustrative cost-sensitive objective in which missed failures and false alarms carry different costs. Under those assumptions, the cost-minimizing threshold moved to 0.105, demonstrating how operational priorities can materially change the preferred decision boundary even when the underlying model stays fixed.

Precision and recall across decision thresholds

Held-out test performance

After model selection and threshold determination were frozen, the final model was evaluated once on the held-out test set.

It achieved:

The final confusion matrix contained:

This makes the trade-off concrete: the selected operating point detected most failures while keeping false alarms very low.

Held-out test confusion matrix

Uncertainty, interpretability and error analysis

Point estimates alone can overstate confidence, especially when the positive class is small. I therefore used bootstrap resampling to estimate uncertainty around the main held-out metrics.

The 95% bootstrap interval for Average Precision was 0.798–0.942, with corresponding uncertainty intervals for precision, recall and F1.

For interpretation, I compared native tree-based feature importance with permutation importance. Rotational speed emerged as the strongest predictor, while the engineered temperature difference, torque × tool wear and power features also contributed meaningful signal.

I also evaluated performance by product type and failure mode rather than relying only on aggregate metrics. This exposed weaker behaviour for rare Tool Wear Failure and Random Failure cases and showed where additional data would be most valuable.

Permutation feature importance for the final model

Engineering the workflow

The project is structured as a reusable Python package rather than a notebook-only analysis.

Dedicated modules cover:

The CLI can regenerate the complete analysis, including the fitted model, selected threshold, metadata, figures and CSV reports.

Automated tests cover the reusable implementation, while the notebook provides the analytical narrative and the CLI provides reproducible end-to-end execution.

Limitations

The AI4I 2020 dataset is synthetic, so these results should not be interpreted as production-ready predictive-maintenance performance.

Real industrial systems would introduce additional challenges such as temporal dependencies, machine-specific histories, sensor drift, changing operating conditions and maintenance costs grounded in real operations.

The project therefore demonstrates a rigorous machine-learning evaluation workflow, not a claim that this specific model is ready for deployment on physical equipment.

What I contributed

What this project demonstrates

This project demonstrates how I approach machine learning as an evaluation and decision-engineering problem, not only a model-fitting task.

It combines data validation, leakage prevention, feature engineering, imbalanced classification, cross-validation, hyperparameter tuning, threshold optimization, uncertainty estimation, interpretability, error analysis and reproducible software engineering in one workflow.

Core technologies: Python · scikit-learn · XGBoost · pandas · NumPy · Matplotlib · Random Forest · Model Evaluation · Feature Engineering · Imbalanced Classification · pytest

View the full analysis notebook →
View source on GitHub →

← Back to projects