This project focuses on Predictive Maintenance (PdM) using the AI4I 2020 Predictive Maintenance Dataset. Unlike traditional reactive maintenance ("fix it when it breaks"), this project aims to predict machine failures before they occur using Machine Learning classification algorithms.
We moved from predicting "Time to Failure" (Regression) to a more strategic approach: "Will it Fail?" (Binary Classification).
Three powerful ensemble learning algorithms were implemented and compared:
- XGBoost (eXtreme Gradient Boosting)
- Random Forest
- LightGBM (Light Gradient Boosting Machine)
Important Note on Data Usage: This project utilizes the original AI4I 2020 Predictive Maintenance Dataset. We strictly adhere to the attribution requirements requested by the original authors.
- Dataset Name: AI4I 2020 Predictive Maintenance Dataset
- Source: UCI Machine Learning Repository
- Original Author: Stephan Matzka, HTW Berlin (University of Applied Sciences)
- DOI / Reference: UCI Repository Link
Please be fair and attribute the original author when using this dataset.
The dataset consists of 10,000 data points stored as rows with 14 features in columns:
- Air temperature [K]: Generated using a random walk process later normalized to a standard deviation of 2 K around 300 K.
- Process temperature [K]: Generated using a random walk process normalized to a standard deviation of 1 K, added to the air temperature plus 10 K.
- Rotational speed [rpm]: Calculated from a power of 2860 W, overlaid with a normally distributed noise.
- Torque [Nm]: Torque values are normally distributed around 40 Nm with a σ = 10 Nm and no negative values.
- Tool wear [min]: The quality variants H/M/L add 5/3/2 minutes of tool wear to the used tool in the process.
- Target:
Machine failurelabel that indicates, whether the machine has failed in this particular datapoint (0 = No Failure, 1 = Failure).
In manufacturing, milling machines fail unexpectedly due to wear, heat, or overstrain. These unplanned downtimes halt production lines and increase costs. The current system operates on a "Reactive Maintenance" logic, which is inefficient.
To develop an AI Classification Model that uses real-time sensor data (temperature, speed, torque, tool wear) to detect the probability of machine failure in advance. This enables a transition to a Predictive Maintenance system.
The analysis pipeline for all three models includes the following steps:
- Data Preprocessing: Cleaning irrelevant columns (UDI, Product ID) and encoding categorical variables.
- EDA (Exploratory Data Analysis): Visualizing target distribution and correlations.
- Handling Imbalance: Using SMOTE (Synthetic Minority Over-sampling Technique) to address the scarcity of failure examples.
- Modeling: Training Random Forest, LightGBM, and XGBoost models.
- Hyperparameter Tuning: Using
RandomizedSearchCVto find optimal parameters. - Evaluation: Comparing models based on Recall, Precision, F1-Score, and Generalization Gap.
- Interpretability: Using SHAP (SHapley Additive exPlanations) to explain feature importance.
We analyzed the models based on three real-world industrial scenarios:
- Context: If a failure occurs, the factory shuts down or safety is compromised. We cannot afford to miss any failure, even if it means checking false alarms.
- Winner: 🏆 Random Forest
- Reason: It missed the fewest failures (Highest Recall), prioritizing safety over precision.
- Context: Maintenance teams are small. Checking false alarms is expensive and time-consuming. We want the model to be sure when it sends an alert.
- Winner: 🏆 LightGBM
- Reason: It had the fewest false alarms (Highest Precision). When it predicts a failure, it is highly likely to be true.
- Context: We want to catch most failures but also keep the maintenance team efficient.
- Winner: 🏆 XGBoost
- Reason: It offered the best trade-off between Recall and Precision, making it the ideal general-purpose model for this dataset.
-
Clone the repository:
git clone https://github.com/Gorkem-Taha/Machine-Failure-Detection-Ensemble.git
-
Install dependencies:
pip install pandas numpy matplotlib seaborn scikit-learn xgboost lightgbm shap imbalanced-learn
-
Run the scripts: You can run any of the model scripts independently:
python random_forest_predictive_maintenance.py python xgboost_predictive_maintenance.py python lightgbm_predictive_maintenance.py
The scripts automatically generate a Reports folder containing:
- Confusion Matrices: To see exact False Negatives and False Positives.
- Feature Importance (SHAP): To understand which sensors (e.g., Torque vs. Rotational Speed) drive the failures.
- Overfitting Analysis: Comparing Train vs. Test scores.
This project's source code is licensed under the MIT License. You are free to use, modify, and distribute the code as long as proper credit is given. See the LICENSE file for details.