Worked Example: A Simple Disruptivity Classifier
A minimal, honest sketch of training and evaluating a disruption predictor, emphasizing correct practice.
Purpose
This page sketches, in outline, how a simple disruption predictor is built and, more importantly, how it is evaluated honestly. It is illustrative pseudocode, not a production system, and uses no real device data. The lessons, group-aware splitting, imbalance handling, and threshold choice, matter more than the specific model.
Setup
Suppose each time slice has a few engineered features and a label: will a disruption occur within the warning horizon. The dataset is grouped by shot and highly imbalanced toward the safe class.
# Illustrative only; not real data or a real device.
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import GroupKFold
from sklearn.metrics import precision_recall_curve
# X: features per time-slice, y: 0 safe / 1 pre-disruptive, groups: shot id
cv = GroupKFold(n_splits=5) # never split a shot across train/test
for train, test in cv.split(X, y, groups):
clf = GradientBoostingClassifier()
clf.fit(X[train], y[train]) # class_weight or resampling for imbalance
scores = clf.predict_proba(X[test])[:, 1]
prec, rec, thr = precision_recall_curve(y[test], scores)
# choose threshold from the cost ratio, not to maximize accuracy
What the code encodes
- Split by shot with GroupKFold, so no shot leaks across the split
- Handle imbalance with class weights or resampling, not raw accuracy
- Evaluate with a precision-recall curve, appropriate for rare events
- Pick the alarm threshold from the real cost of misses versus false alarms
What is missing
A real system uses time-ordered splits for causal real-time use, reports the warning-time distribution, quantifies uncertainty across folds, tests cross-machine transfer, and includes out-of-distribution checks. It also connects the alarm to an avoidance or mitigation action, which is where the physics value lies.
The point
The model is the easy part. The discipline around it, honest splitting, imbalance-aware metrics, calibrated thresholds, and reproducible evaluation, is what makes a disruptivity classifier trustworthy rather than merely accurate-looking.