Skip to Content
Course content

216: Capstone: Building an End-to-End Predictive Maintenance Model

Click on the "Edit" button in the top corner of the screen to edit your slide content.

Think of predictive maintenance like being a seasoned mechanic who can tell a car's engine is about to blow just by listening to the idle. You aren't guessing; you're recognizing a pattern. You've heard that specific high-pitched whine a thousand times, and you know that three days later, a belt usually snaps. You're essentially taking "sensor data" (the sound, the smell of burnt oil, the vibration in the steering wheel) and mapping it to a future event (the breakdown).

In this capstone, we're doing exactly that with R, but instead of a car, we're monitoring industrial pumps. Here is how our code maps to that mechanic's intuition:

  • The Sensor Data: These are our features—temperature, vibration frequency, and pressure readings.
  • The Mechanic's Experience: This is our training set. We're showing the model thousands of hours of "normal" operation versus the hours leading up to a "failure."
  • The Warning Light: This is our model's prediction. We don't just want to know if it's broken now; we want a signal that it's going to break.

Wrestling with Sensor Noise

Real-world sensor data is messy. It jitters. If you feed raw, second-by-second vibrations into a model, you'll just be modeling the noise. I've found that the secret to predictive maintenance isn't the algorithm, but the windowing. We need to look at the rolling average or the standard deviation over the last hour to see the actual trend.

library(tidyverse)
library(tidymodels)
library(slider)

# Let's assume 'pump_data' has: timestamp, pump_id, temp, vibration, failure
# We create a rolling average to smooth out the spikes
processed_data <- pump_data %>%
    group_by(pump_id) %>%
    mutate(
        temp_roll_avg = slide_dbl(temp, mean, .before = 10),
        vib_roll_std  = slide_dbl(vibration, sd, .before = 10)
    ) %>%
    ungroup() %>%
    drop_na()

Teaching the Model to Spot Red Flags

Since we're predicting a binary outcome (Failure vs. No Failure), a Random Forest is usually my go-to here. It handles the non-linear relationships between temperature and vibration much better than a simple logistic regression would. If the temperature is high and the vibration is erratic, that's a red flag, even if neither value is "critical" on its own.

# Define the recipe
pump_recipe <- recipe(failure ~ temp_roll_avg + vib_roll_std + operating_hours, data = train_data) %>%
    step_normalize(all_predictors())

# Set up the Random Forest model
rf_spec <- rand_forest(trees = 500) %>%
    set_engine("ranger", importance = "impurity") %>%
    set_mode("classification")

# Create the workflow
pump_workflow <- workflow() %>%
    add_recipe(pump_recipe) %>%
    add_model(rf_spec)

# Fit the model
final_fit <- pump_workflow %>% fit(data = train_data)

The High Cost of Being Wrong

Here is where most people mess up: they look at "Accuracy." In predictive maintenance, accuracy is a lie. If 99% of your machines are running fine, a model that simply guesses "No Failure" every single time is 99% accurate—and completely useless. It would let every single pump explode.

I care about Recall (Sensitivity). I'd rather have a few "false alarms" (sending a technician to check a healthy pump) than one "false negative" (a pump exploding and shutting down the whole factory). When you evaluate your model, look at the confusion matrix specifically for those missed failures.

# Evaluate using the test set
results <- predict(final_fit, test_data) %>%
    bind_cols(test_data)

conf_mat(results, truth = failure, estimate = .pred_class)

# Check the recall specifically
metrics(results, truth = failure, estimate = .pred_class) %>%
    filter(.metric == "recall")



📋 Practical Task

Capstone Project: Predicting Wind Turbine Bearing Failures

You have been handed a dataset containing SCADA (Supervisory Control and Data Acquisition) data from a wind farm. The dataset includes wind speed, generator temperature, and gearbox vibration levels. Some turbines failed due to bearing wear, and we have the logs of when those failures occurred.

Your Goal: Build a predictive pipeline in R that flags a turbine for maintenance before it fails.

Requirements:

  • Feature Engineering: Use the slider package or dplyr to create a 24-hour rolling average for gearbox vibration. Raw vibration is too volatile; the trend is what matters.
  • Model Selection: Implement a classification model (Random Forest or XGBoost) using the tidymodels framework.
  • Optimization: Instead of maximizing overall accuracy, tune your model's threshold or evaluate it based on Recall. You must demonstrate that you are prioritizing the detection of failures over the avoidance of false positives.
  • Validation: Produce a confusion matrix and a ROC curve to justify why your model is "safe" enough to be used in a real wind farm.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.