A threshold looks like the simplest thing in monitoring and is in practice where most of the trust is won or lost. Set it too tight and the alert is noise; set it too loose and the alert is useless; set it without hysteresis and it oscillates; set it without a hold-down and it fires on every transient.
This post is about choosing all four numbers deliberately: the threshold, the deadband, the delay-on, and the delay-off.
Thresholds come from data, not from datasheets
The datasheet gives you the destructive limit. Operators care about the actionable limit, which is lower and usually not documented anywhere.
Three sources, in order of usefulness:
1. Historical distribution per operating mode. Compute quantiles on healthy data, conditioned on mode:
import numpy as np
def suggest_threshold(values_by_mode: dict[str, np.ndarray], q=0.999, margin=1.15):
"""Threshold above the healthy tail, per mode, with a safety margin."""
out = {}
for mode, v in values_by_mode.items():
base = float(np.quantile(v, q))
out[mode] = base * margin if base > 0 else base - abs(base) * (margin - 1)
return out
The q=0.999 choice implies roughly one false excursion per 1,000 windows. At a 10 s hop that is one every ~2.8 hours of operation per mode per device — which is almost certainly too many for a 500-device fleet. Do the arithmetic before you pick the quantile:
false alarms/day = devices × samples/day × (1 − q)
500 devices × 8,640 windows/day × 0.001 = 4,320/day
This is why naive statistical thresholds fail at fleet scale: a per-device 0.1% false positive rate is 4,320 alerts a day across the fleet. Either raise the quantile substantially (0.9999 is a reasonable starting point for a big fleet), require corroboration, or accept a two-stage design where a cheap threshold triggers a confirmation.
2. Cost-based thresholds. When you know the cost of a false alarm and the cost of a missed fault, the threshold follows:
def cost_optimal_threshold(scores, is_fault, c_fn, c_fp):
"""Pick the threshold minimising expected cost."""
order = np.argsort(scores)
s, y = scores[order], is_fault[order]
best, best_t = None, None
for i in range(1, len(s)):
t = s[i]
pred = scores >= t
fn = np.sum(~pred & is_fault)
fp = np.sum(pred & ~is_fault)
cost = fn * c_fn + fp * c_fp
if best is None or cost < best:
best, best_t = cost, t
return best_t, best
With c_fn = 5,000 (unplanned downtime) and c_fp = 120 (technician dispatch), the optimum lands far to the false-positive side of the accuracy-optimal threshold. That is not a bug — it is the correct trade for the actual costs, and it is the kind of decision an operator can review.
3. Operator interviews. Ask three technicians what number makes them walk to the machine. Their answers will disagree by a factor of two, and the disagreement is the most valuable output — it identifies the cases where the process genuinely differs.
Hysteresis: two thresholds, one concept
Hysteresis means raising at one level and clearing at a lower one. The gap is the deadband, and its minimum size is set by the noise amplitude:
class Hysteresis:
def __init__(self, high: float, low: float):
if low >= high:
raise ValueError("low must be below high")
self.high, self.low = high, low
self.state = False
def update(self, x: float) -> bool:
if not self.state and x >= self.high:
self.state = True
elif self.state and x <= self.low:
self.state = False
return self.state
Choosing the deadband:
- Measure the noise band of the signal in steady state (p5–p95 over a healthy hour).
- Set
highat least one noise band above the actionable level, andlowat least one noise band below it. - If the resulting deadband is so wide that it hides a genuine excursion, the signal needs smoothing (rolling mean over 3–5 samples) rather than a wider band.
A rule of thumb: deadband ≈ 2× the steady-state noise amplitude, expressed in the same units as the threshold. For a vibration channel with 0.4 mm/s peak-to-peak noise around an action limit of 7.1 mm/s, a deadband of 0.8 mm/s (raise at 7.5, clear at 6.7) removes most oscillation without hiding a real rise.
Hold-downs: matching the time constant of the physics
Hysteresis handles amplitude oscillation. Hold-downs handle time.
Delay-on suppresses transients: the condition must persist for N samples before firing. Choose N from the fastest genuine fault you must catch, not from convenience:
delay_on_s ≤ time_to_damage − notification_and_response_s
For a bearing that reaches destructive vibration in ~10 minutes with a 3-minute response, a delay-on of up to 5 minutes is free. For a pressure excursion that ruptures a line in 10 seconds, delay-on must be zero and the decision must live on the device.
Delay-off (dwell) prevents premature resolution: the condition must be clear for M samples before clearing. Delay-off is usually 2–3× delay-on, because false recovery is more common than false trigger with noisy sensors.
class HoldDown:
def __init__(self, delay_on: int, delay_off: int):
self.delay_on, self.delay_off = delay_on, delay_off
self.state = False
self._n = 0
def update(self, cond: bool) -> bool:
if cond == self.state:
self._n = 0
return self.state
self._n += 1
need = self.delay_off if self.state else self.delay_on
if self._n >= need:
self.state = cond
self._n = 0
return self.state
Rate-of-change thresholds deserve their own rule rather than being folded into the level threshold. A temperature of 60 °C is normal; a rise of 5 K/min is not. Emitting temp > 60 and d(temp)/dt > 5 as separate rules with separate severities gives the operator actionable information instead of an ambiguous "temperature problem".
Calibrate before you threshold a model score
Applying a 0.8 threshold to an uncalibrated model output is a common and expensive mistake. A raw softmax or sigmoid output is not a probability, and 0.8 may correspond to a 40% empirical precision.
Calibrate on a held-out set, then threshold the calibrated value:
from sklearn.isotonic import IsotonicRegression
def calibrate(scores_val, labels_val, scores_test):
iso = IsotonicRegression(out_of_bounds="clip").fit(scores_val, labels_val)
return iso.predict(scores_test)
After calibration, score > 0.9 means "roughly 90% of these were faults in the validation period", which is a statement an operator can act on. Re-calibrate whenever the model or the population changes; calibration drift is one of the first symptoms of concept drift.
An alert budget beats an accuracy target
The most useful tuning constraint I have found is a budget, agreed with the team that receives the alerts:
"This fleet may generate at most 15 interrupts per week. Anything above that goes into the digest."
Then tune thresholds to fit the budget at fixed precision, rather than chasing F1. The process:
- Collect two weeks of events with scores and operator dispositions (actionable / not).
- Sort candidate threshold settings by precision.
- Pick the tightest setting that stays under the budget.
- Review weekly; adjust the budget explicitly when the fleet grows.
This inverts the usual conversation. Instead of arguing about whether 0.78 or 0.82 is better, the team decides how much interruption it can absorb, and the thresholds follow. It also makes fleet growth a first-class input: doubling the device count at constant per-device rates doubles alerts, so the budget forces the threshold tighter — which is exactly the right pressure.
A tuning sheet worth keeping per rule
rule: vib.high
units: mm/s RMS
thresholds: { run: 7.1, idle: 4.5 }
hysteresis: { high: 7.5, low: 6.7 }
delay_on_samples: 6 # 60 s at 10 s hop
delay_off_samples: 18 # 180 s
corroboration: [temp_rate, current]
severity: warn → critical at 11.0
suppress_in_modes: [maintenance, defrost]
rationale: >
ISO 10816 zone C/D boundary for group 2 machines.
Historical p99.95 in run mode is 6.2; 7.1 gives ~1 false
excursion per device per 3 weeks after hysteresis.
owner: reliability-team
last_reviewed: 2026-11-20
Three fields do most of the long-term work: rationale (so the next person does not "simplify" a deliberate choice), owner (so it has one), and last_reviewed (so stale rules get found). A rule set without these becomes folklore within a year.
The operational test
The question that matters is not "is the threshold statistically justified" but "would an operator act on this alert at 3 a.m.?"
Run this test on your last 50 alerts. If fewer than half would produce an action, the thresholds are too tight — regardless of what the statistics say. If almost all are actionable but you missed a known incident, they are too loose. There is no third failure mode, and no metric that substitutes for reading the alerts.
Next: Shadow Mode and Safe Rollback — Shipping Model Updates to an Edge Fleet.
Top comments (0)