Alert thresholds, precision and recall
Why a single accuracy percentage can hide failure on rare events.
Seven experiments show when each method works and when it can mislead.
Moving through the seven experiments and reading a threshold.
Lab is a playground for the methods behind industrial AI. Pit five anomaly detectors against the same data, and see which one catches the spike, the drift, or the shift. Slide the threshold, and watch the trade-off between false alarms and missed events. Explore OEE, process capability, PID tuning, aliasing and forecasts, each with a plain verdict. It runs in C and WebAssembly, in your browser. The data is synthetic: methods, not field accuracy.
Narration: synthetic voice (Piper, voice “Joe”, CC0 public domain). Captions are burned into the video.
The maths
F1 = 2PR / (P + R)
All are synthetic; the test is the last half of the series.
1 is balanced; raising it adds alarms.
Computing…
Shaded areas are the true events.
Red cell: alarm. Top lane: true events.
A high F1 means precision and recall are both good.
| Method |
|---|
The first 200 rows train, the last 200 test; every count is from the test part.
Robust z: ỹ and MAD from training; s is the sensitivity.
Regression residual: a least-squares line fitted on training.
EWMA, λ = 0.2. r: the residual from a baseline of a line plus one sine (period 8–120, least RSS) fitted on training.
CUSUM: d = r / σ̂, k = 0.5.
Isolation Forest: features are the value, its difference, and the mean and spread of the last 5 values; 100 trees, ψ = 128; the threshold is clipped to [0.5, 0.999].
Counting is per row: a 30-row burst is 30 positives, a single spike is 1. A drift counts as an event once it exceeds the noise (σ/0.04 rows after it starts).
| Setting | Value | Note |
|---|---|---|
| Verdict | F1 ≥ 0.7 · ≥ 0.4 | good · watch · otherwise attention |
Source lab/lab.js · wasm/kutupml.js · dev/native/kutupml.c
The maths
The series comes from experiment 1.
The threshold is in the method’s own units.
Computing…
Up and right is better. Marked point: current threshold.
The peak is the threshold with the best F1.
The threshold is picked on the test part, so the result is optimistic.
A 201-step grid; the first threshold with the best F1.
| Setting | Value | Note |
|---|---|---|
| Verdict | ≥ 0.9 · ≥ 0.6 | F1(t) / F1(t*): good · watch · otherwise attention |
t* is searched on the test part, so the best F1 shown is optimistic; in real use the threshold should be chosen on separate validation data.
Source lab/lab.js · wasm/kutupml.js · dev/native/kutupml.c
The maths
Computing…
From planned time, each loss is subtracted in turn; OEE remains.
The needle shows OEE; colours mark the 60% and 85% bands.
The 85% line is a benchmark, not your target.
Times in minutes, the ideal cycle in seconds per unit; the 60 makes them match.
Waterfall losses in percentage points of planned time; the order is fixed (stops, speed, quality).
| Setting | Value | Note |
|---|---|---|
| Verdict | 85% | OEE ≥ 85% good, else watch; P > 100% raises an input warning and is not clipped |
Source lab/lab.js · wasm/analytics.js
The maths
One measurement per line. At least 20.
Computing…
Red bars are outside specification. The dashed curve is the normal distribution.
Short-term spread from consecutive differences (d₂ = 1.128 for n = 2). The data order matters.
s: the standard deviation of the whole sample (n − 1).
Assumes a normal distribution; uses the overall s, not σ_w.
Jarque–Bera normality test (g₁ skewness, g₂ kurtosis); a warning if p < 0.05.
| Setting | Value | Note |
|---|---|---|
| Verdict | Cpk ≥ 1.33 · ≥ 1.0 | good · borderline · otherwise attention; off-centre note if Cp − Cpk > 0.2 |
| Histogram | 24 | bins over a range that also covers the spec limits |
Source lab/lab.js · wasm/kutupml.js · dev/native/kutupml.c
The maths
Computing…
The dashed line is the expected response if the suggestion is applied.
The output is limited between 0% and 100%.
First-order process with dead time; explicit Euler, Δt = 0.1 s, 240 s. The dead time adds one extra sample: the effective delay is θ + 0.1 s.
The derivative acts on the filtered measurement, not the error, so a setpoint change gives no kick.
Back-calculation anti-windup.
| Setting | Value | Note |
|---|---|---|
| Setpoint · disturbance | 50 · −15 | added to the output from t ≥ 120 s |
| Rise · settling | 10–90% · ±2% | settling is searched only in the first 120 s; overshoot and IAE cover all 240 s |
| Suggestion grid | 11 × 5 × 2 = 110 | Kp ∈ {0.2 … 12}, Ti ∈ {2, 4, 8, 16, 32}, Td ∈ {0, Ti/8} |
| Suggestion rule | least IAE | among runs with overshoot ≤ 20% and final error ≤ 1; for this process model only |
| Verdict | 25% · 10% · 60 s | not settled or overshoot > 25% attention; overshoot > 10%, settling > 60 s or not reaching 90% watch |
Source lab/lab.js · wasm/kutupml.js · dev/native/kutupml.c
The maths
A one-second record. The sampling rate fs is the number of samples per second.
Computing…
Dots are samples; the line passes through them.
A marker at the apparent frequency (not a computed spectrum), the true frequency and the Nyquist limit.
Example: f = 60 Hz, fs = 50 Hz → fN = 25 Hz, apparent 10 Hz.
f < fs/2 counts as faithful, f = fs/2 as the edge, f > fs/2 as aliased. The “apparent frequency” chart is a marker at fapp, not a computed spectrum. No anti-aliasing filter is modelled.
Source lab/lab.js
The maths
240 hours: 192 training, 48 test.
Computing…
Vertical line: training | testing.
A shorter bar is better.
| Method | MAE |
|---|
192 hours train, 48 test.
24-hour average: the mean of the last 24 training hours.
Damped Holt: α, β, φ from a 7 × 4 × 4 = 112 grid that minimises one-step-ahead MAE on training.
Kalman local linear trend with a damped slope: noises and κ by maximum likelihood (Nelder–Mead); the forecast applies this transition h times.
Denominator: the mean absolute error of the one-step naive forecast on training.
| Setting | Value | Note |
|---|---|---|
| Verdict | seasonal naive | watch if naive, 24-hour, Holt or Kalman beats it on MAE; otherwise good |
Source lab/lab.js · wasm/kutupml.js · dev/native/kutupml.c
Each experiment’s “Technical detail” panel gives the formulas and the values in the code; short definitions of the terms are here.
It shows when common engineering and data methods work and when they can mislead, through small experiments.
No. Calculations run in your browser; numbers you paste are not sent to any server.
Why a single accuracy percentage can hide failure on rare events.
Let’s review your data source, your existing system and the decision you want to improve.