Anomaly Detection: Catching the Outliers Supervised Learning Misses
The pass/fail classifier from earlier in this track can only recognize failure patterns it's already seen. This page is about the ones it hasn't.
Advanced
touches_slow_suite. Now imagine a genuinely new failure mode shows up — a
poisoned dependency that silently corrupts build artifacts, something that has never occurred
in the training data and doesn't resemble any failure the model has seen. A supervised
classifier has no mechanism to flag it; it was only ever taught to recognize the specific
patterns present in its training examples, and this one isn't among them. Anomaly
detection reframes the question entirely: instead of "does this match a known failure
pattern," it asks "does this run look statistically normal at all" — a question that doesn't
require ever having seen the specific way it's about to go wrong.
mean = (1/m) * sum(x_i for i in 1..m)
variance = (1/m) * sum((x_i - mean)^2 for i in 1..m)
# for a new value x, its probability density under this Gaussian:
p(x) = (1 / sqrt(2*pi*variance)) * exp(-(x - mean)^2 / (2*variance))
p(run) = p(duration) * p(lines_changed) * p(files_changed) * ...
p(run) < epsilon, for some threshold
epsilon chosen the same disciplined way every other hyperparameter in this track
has been: never guessed, always tuned against held-out data. Say the CI history has 10,000
normal runs and only 20 confirmed anomalies — split similarly to
Train/Test Splits & Cross-Validation, fit the Gaussian
parameters (mean, variance) on the training split of normal runs only, then use the validation
split — normal runs plus most of the known anomalies — to sweep candidate values of
epsilon and pick whichever one gives the best F1 score from
Evaluation Metrics. With only 20 positive examples total,
this is about as extreme a class-imbalance problem as this track has covered — precision and
recall matter far more here than accuracy ever could.
| Use anomaly detection when | Use supervised learning when |
|---|---|
| very few labeled positive examples exist | plenty of labeled positive examples exist |
| those few examples don't cover every way things can go wrong | the labeled examples reasonably cover the full range of failure types expected in production |
| future failures may look nothing like any failure seen so far | future failures are expected to resemble past ones |
lines_changed, for instance) usually benefit
from a transform — a log transform is a common first choice — to make them look closer to
Gaussian before fitting, since the whole model is built on that assumption.