Applied extension

Neural networks for anomaly detection

Build an anomaly detector that people can review and trust.

From layers to learning

A dense neural-network layer computes z = Wx + b, then h = φ(z). The weights W mix input features; biases b shift the response; the activation φ introduces nonlinearity. Without nonlinear activations, a stack of dense layers collapses to one affine transformation. ReLU uses max(0, z), while a linear output is often suitable for reconstructing standardized continuous measurements. Architecture should reflect the data, not merely sound sophisticated.

A forward pass carries a batch through these layers and computes a loss. Backpropagation applies the chain rule backward to calculate each parameter's contribution to that loss. For a scalar prediction ŷ = wx and loss L = (ŷ − y)², the derivative is ∂L/∂w = 2(wx − y)x. With x = 2, y = 3, and w = 1, the derivative is −4; a gradient step with learning rate 0.1 changes w to 1.4, moving ŷ from 2 to 2.8.

Mini-batches average gradients across several examples, trading memory and throughput against noisy updates. Small batches can be noisy; very large batches consume memory and may require retuning. Adam tracks moving averages of gradients and squared gradients, with bias correction, to adapt update sizes. It still needs a sensible learning rate. Too large a rate can cause oscillation or divergence; too small a rate wastes training time. Inspect training and validation curves rather than trusting a completed run.

Autoencoders and reconstruction scores

An autoencoder learns to reconstruct its input through an encoder, a lower-dimensional bottleneck, and a decoder. The bottleneck encourages a compact representation of normal operating relationships. An overly expressive network may simply copy anomalous inputs, defeating detection. Regularization, early stopping, and a deliberately restricted architecture help, but no architecture guarantees useful anomalies.

Fit scaling only on training data. Otherwise future or anomalous measurements influence the representation. Without scaling, a temperature measured in hundreds can dominate vibration measured in fractions. For standardized input x and reconstruction x̂, one score is s(x) = (1/d) Σⱼ(xⱼ − x̂ⱼ)². A three-feature residual vector (0.2, −0.4, 1.0) gives s = 0.40. The score measures reconstruction error; it is not a probability of failure. Feature-level residuals can guide expert inspection, although correlated features complicate attribution.

Clean splits before thresholds

Split by time and by the deployment unit, such as machine or production run. Adjacent readings from the same incident must not land in both training and test data. Random row splits can reward memorization of machine identity or repeated operating cycles. Reserve representative, expert-reviewed normal validation data for threshold selection and keep a separate, untouched test period. If only previously seen machines will be served, state that narrower evaluation scope explicitly.

Training contamination teaches a reconstruction model to reproduce some failures. Validation contamination can inflate a high-quantile threshold and hide those failures. Investigate suspicious segments, document uncertain labels, and compare robust training choices rather than declaring every unlabeled point normal. When trustworthy clean validation is unavailable, acknowledge that the false-alert estimate is uncertain and start with a reviewed pilot.

DecisionWorked operating example
Alert budget10,000 normal windows per day; at most 20 false alerts per day.
Candidate thresholdThe clean validation 99.8th percentile targets approximately 0.2% window-level false alerts.
Reality checkThat is about 20 flagged normal windows daily only if deployment resembles validation; correlated windows and alert grouping change event counts.

Evaluate event-level recall, detection delay, precision after review, and false alerts per day, not just an aggregate ranking score. A fault lasting fifty windows should not count as fifty independent successes. Report the number of incidents and machines behind estimates. Tune event grouping and cooldown rules on validation data, then freeze them with the model and threshold before testing.

Baselines, diagnostics, and distribution shift

Compare the neural model against a robust z-score using a training median and median absolute deviation, simple domain limits, and IsolationForest. Baselines are cheaper to debug and may work better with limited data. Use identical splits and alert budgets. Examine residuals by machine, load, shift, and sensor condition; a model that only detects missing sensors may miss the business objective. See ensembles, validation, and evaluation.

Distribution shift occurs when new materials, maintenance, or sensor calibration changes incoming data. Track score distributions, feature ranges, missingness, and reviewed outcomes. A rising alert rate may indicate a process problem or a broken detector. Route representative alerts and some non-alerts to experts, preserve versioned review decisions, and require approval before recalibrating thresholds. Never silently normalize away a genuine safety signal.

Why not choose the threshold that catches every historical fault?

It may overfit a small, biased incident set and create an unmanageable alert burden. Choose the operating point on validation data using explicit costs and review capacity; report test recall and false alerts separately.

What would justify using a neural model?

A reproducible improvement over simpler baselines at the same alert budget, across realistic held-out groups and periods, with acceptable latency, stable diagnostics, and an expert-review process.

Definition

View in glossary →