Learning Data Science: Predictive Maintenance with Decision Trees | R bloggers

- Advertisement -

Predictive maintenance is one of the big revolutions happening right now across all major industries. Even after parts are regularly replaced or fail, it uses machine learning methods to predict when a part is about to fail.

- Advertisement -

If you want to get an introduction to this exciting growing field, read on!

- Advertisement -

Wikipedia defines predictive maintenance as:

Predictive maintenance techniques are designed to help determine the condition of in-service equipment in order to predict when maintenance should be performed. This approach promises cost savings over routine or time-based preventive maintenance, as tasks are performed only when warranted. […]

- Advertisement -

Predictive maintenance differs from preventive maintenance in that it relies on the actual condition of equipment rather than average or expected life figures to predict when maintenance will be needed. Typically, machine learning approaches are adopted for the definition of the real state of the system and for forecasting its future state.

So, without further ado, let us get started with this tempting content!

We use a synthetic dataset that reflects real predictive maintenance data (the data was kindly provided by my colleague Professor Stefan Matzka from HTW Berlin University of Applied Sciences and can be found here: UCI Machine Learning Repository).

The dataset consists of 10,000 data points that are stored as rows with 6 features in columns:

Product ID (consisting of the letters L, M, or H as low (50% of all products), medium (30%), and high (20%) product quality variants) air temperature [K]
process temperature [K]
rotational speed [rpm]
torque [Nm]
tool wear [min]
Machine failure (indicates whether the machine has failed)

Since this is a synthetic dataset for illustrative purposes only, we do not provide any specific time frame within which actual maintenance should occur after a “machine failure” is triggered.

A characteristic of data in this domain is that they are apparently highly imbalanced as fortunately this is not often the case:

machine_data <- read.csv("data/ai4i2020.csv") machine_data <- data.frame(machine_data)[-9]machine. failure = factor(machine_data$machine.failure)) table(machine_data$machine.failure) ## ## 0 1 ## 9661 339

Machine learning algorithms often have difficulties with such data because they can be confounded by the fact that the simplest of all models, i.e. “never fails” achieves an accuracy of around 97% in this case (might be more on that problem) found here: ZeroR: The Simplest Possible Classifier, or Why High Accuracy Can Be Deceptive).

Therefore, we strive for an accuracy that is much higher than that! Another thing is that it would be nice to have a model that can be interpreted by an expert, such as an engineer.

One class of models that often strike a balance between those two conflicting goals are decision trees (see also: Learning Data Science: Predicting Income Brackets).

The following image gives a fun example of how decision trees work:

Nevertheless, in machine learning we don’t want to build the decision tree ourselves, but let the machine do it (all used packages can be installed from CRAN):

library(oneR) library(rpart) library(rpart.plot) pm_model <- rpart(machine.failure~type + air.temperature..k..Nm. + tool.wear..min., data = machine_data) rpart .plot(pm_model, type = 5, extra = 0, box. Palette = "Grays")

The decision tree is quite complex but should still be interpreted by an expert. We used the entire dataset to build it. To get an idea of ​​how well it will perform in real life, we train it with a 70% sample of the data and test it with the remaining 30%:

group. seed(12) random <- sample(1: nrow(machine_data), 0.7 * nrow(machine_data)) machine_data_train <- machine_data[random, ]machine_data_test <- machine_data[-random, ]pm_model <- rpart(Machine.failure ~ Type + Air.temperature..K. + Process.temperature..K. + Rotational.speed..rpm. + Torque..Nm. + Tool.wear..min., data = machine_data_train) predict <- predict(pm_model, machine_data_test, type="class") eval_model(predict, machine_data_test) ## ## confusion matrix (absolute): ## actual ## predict 0 1 sum ## 0 2895 35 2930 # # 1 9 61 70 ## sum 2904 96 3000 ## ## confusion matrix (relative): ## actual ## prediction 0 1 sum ## 0 0.96 0.01 0.98 ## 1 0.00 0.02 0.02 ## sum 0.97 0.03 1.00 ## ## Accuracy: ## 0.9853 (2956/3000) ## ## Error rate: ## 0.0147 (44/3000) ## ## Reduction in error rate (vs. base rate): ## 0.5417 (p-value = 1.441 E-09)

The accuracy is now up to about 99%, with a statistically significant error rate reduction of over 50% compared to our intuitive (and not very useful) model from above.

So, we achieved both goals, explainability and high accuracy with our decision tree – quite an impressive feat!

As more and more companies wish to switch from traditional to predictive maintenance, I myself was a lead consultant for a large project in a multinational chemical industry group. If you have experience in this fascinating area, please share some examples with us in the comments!


Source link

- Advertisement -

Recent Articles

Related Stories