What You Will Learn
In the beginner guide (Guide 17) you detected anomalies in BFP sensor data. Now you will go further: classifying what type of fault is occurring by fusing multiple sensor signals, training a Random Forest multi-class classifier, and explaining its decisions with SHAP. In this guide you will:
- Load and filter BFP time-series data to running conditions
- Engineer features from raw sensor channels (rolling stats, ratios, deltas)
- Label fault windows using alarm and trip log data
- Train a Random Forest classifier for multi-class fault diagnosis
- Evaluate with confusion matrix, precision, recall, and F1
- Use SHAP to explain which sensors drive each fault prediction
- Build a sliding-window real-time fault detector
Prerequisites: This guide builds on concepts from Guide 17: BFP Health Monitoring. Complete that guide first if you are new to the BFP dataset.
SP&L Data You Will Use
- bfp_train_hourly.parquet — 8,784 rows x 88 columns of hourly BFP and system data
- alarm_log.csv — timestamped alarm events with tag, severity, and description
- trip_log.csv — unit trip events with cause codes and affected equipment
- tag_dictionary.csv — maps tag names to engineering descriptions and units
Additional Libraries
Which terminal should I use? On Windows, open Anaconda Prompt from the Start Menu (or PowerShell / Command Prompt if Python is already in your PATH). On macOS, open Terminal from Applications → Utilities. On Linux, open your default terminal. All pip install commands work the same across platforms.
Verify Your Setup
Before starting, verify that your environment is configured correctly. Run this cell first to confirm all dependencies are installed and data files are accessible.
Working directory: All guides assume your working directory is the repository root (Dynamic-Network-Model/). Start Jupyter Lab from there: cd Dynamic-Network-Model && jupyter lab
Extra dependency: pip install shap
Having trouble? Check our Troubleshooting Guide for solutions to common setup and data loading issues.
Load & Filter Data
Feature Engineering
Raw sensor values alone are not sufficient for fault classification. We need to engineer features that capture the dynamic behavior of the equipment: rolling statistics, cross-sensor ratios, and rate-of-change indicators.
Why these features? Rolling standard deviation captures volatility that precedes failures. Rate-of-change (delta) detects rapid deterioration. Cross-sensor ratios reveal imbalances: a healthy pump has roughly equal DE and NDE bearing temperatures, so a ratio drifting away from 1.0 signals uneven wear or lubrication issues. These engineered features give the classifier far more diagnostic power than raw values alone.
Label Fault Windows
We need labeled data to train a classifier. The alarm and trip logs provide timestamps of known fault events. We will label each hour in the time series as one of several fault categories based on proximity to alarm events.
Fault window size: A 4-hour window captures the lead-up to and aftermath of each fault event. Plant data typically shows sensor drift in the hours before an alarm fires. Wider windows capture more precursor behavior but risk labeling normal operation as faulty. Start with 4 hours and adjust based on your confusion matrix results.
Train the Classifier
Evaluate with Confusion Matrix
Reading the confusion matrix: Each row is the true fault type, each column is the predicted type. The diagonal shows correct predictions. Off-diagonal entries show misclassifications. For rotating equipment, confusing "vibration_fault" with "bearing_fault" is common because high vibration often causes bearing damage. The classification report shows precision (of all predicted bearing faults, how many were correct?) and recall (of all actual bearing faults, how many did the model find?).
SHAP Analysis
SHAP (SHapley Additive exPlanations) provides a mathematically rigorous way to explain why the model made each prediction. For each sample, SHAP assigns a contribution value to every feature, showing which sensors pushed the prediction toward each fault class.
What SHAP tells you: If the bearing temperature rolling standard deviation is the top SHAP feature for "bearing_fault", it means the model learned that volatile bearing temperatures are the strongest indicator of bearing problems. This aligns with engineering knowledge: a failing bearing exhibits erratic temperature swings before a sustained rise. SHAP converts a black-box model into an interpretable diagnostic tool that plant engineers can trust.
Sliding Window Detection
In a real plant, data arrives hour by hour. We simulate a real-time fault detector that processes each hour as it arrives, maintains a sliding window of recent predictions, and raises an alarm when a fault type is consistently predicted.
What You Built and Next Steps
- Loaded BFP time-series, alarm, and trip data from the SP&L generation dataset
- Engineered features from rolling statistics, rate-of-change, and cross-sensor ratios
- Labeled fault windows from alarm events with automatic fault-type classification
- Trained a Random Forest multi-class classifier with class-weight balancing
- Evaluated with confusion matrix and per-class precision/recall/F1
- Used SHAP to explain which sensors drive each fault type's prediction
- Built a sliding-window real-time fault detector with configurable alarm thresholds
Ideas to Try Next
- XGBoost comparison: Replace Random Forest with XGBoost and compare accuracy and SHAP explanations
- Hyperparameter tuning: Use
GridSearchCVto optimize tree depth, number of estimators, and leaf size - Temporal features: Add hour-of-day and day-of-week features to capture operational cycle effects
- BFP B fusion: Include BFP B sensors as additional features for cross-pump fault detection
- LIME comparison: Use
limefor local explanations and compare with SHAP
Key Terms Glossary
- Random Forest — an ensemble of decision trees that votes on the final prediction; robust to overfitting and handles class imbalance
- Multi-class classification — predicting one of several discrete categories (not just binary yes/no)
- SHAP (SHapley Additive exPlanations) — a game-theory-based method for explaining individual model predictions by assigning contribution values to each feature
- Confusion matrix — a table showing how many samples of each true class were predicted as each class; the diagonal represents correct predictions
- Feature engineering — creating new input variables from raw data to capture patterns that improve model performance
- Sliding window — a fixed-size buffer of recent observations that advances as new data arrives; used for real-time monitoring
- Class weight balancing — adjusting the loss function to penalize misclassification of rare classes more heavily
- Sensor fusion — combining data from multiple sensors to achieve more reliable and informative measurements than any single sensor provides
Ready to Level Up?
In the next guide, you'll build a physics-informed digital twin that compares actual BFP performance against OEM pump curves.
Go to BFP Digital Twin & Performance Tracking →