AI State of the Art
Domains/Séries temporelles/29 min
Section 236

Anomaly Detection: Sensors and Predictive Maintenance

Listen as a podcast →

A story: the night watchman who knows the factory's hum

A night watchman has walked the same factory floor for twenty years. He could not describe precisely what the machines' "normal" sound is, but if a bearing starts whining one octave too high, he stops dead. He does not know what he is looking for; he knows what stands out. And he knows it because he has heard ten thousand normal nights.

That is exactly the programme of anomaly detection in time series: learn what a system's normal behaviour looks like (a machine, a payment network, a human heart) in order to spot the moment it departs from it. You do not learn to recognise the breakdown (you have almost never seen one); you learn the normal, and the anomaly is whatever does not resemble it.

Where this page sits in the module

Anomaly detection is one of the four main time-series tasks introduced in the overview, alongside forecasting, classification and imputation. It gets its own page because it dominates real industrial deployments, and because it has methods and pitfalls all of its own.

The problem, and why it matters so much

Three settings dominate, and the first is probably the number-one industrial use case of this whole module:

  • Predictive maintenance. A machine almost never fails all at once: it drifts. A bearing wears down, a vibration changes its signature, a temperature creeps up a few degrees over weeks. Detecting that drift in sensor curves means replacing the part before it breaks, instead of halting an entire production line in an emergency, or waiting for a critical component to give out mid-flight. Industry everywhere (energy, transport, chemicals, manufacturing) stuffs its equipment with sensors for this reason.
  • Fraud. In a stream of bank transactions, fraud is an anomaly: spending behaviour that does not match the customer's history.
  • Medical monitoring. An electrocardiogram, oxygen saturation, continuous glucose readings: detecting the abnormal episode means raising the alert in time.
What a drift looks like, concretely

Take a motor's ball bearing. When new, it vibrates with a characteristic signature. When a microscopic crack appears on one ball, every pass of the ball over the crack adds a small periodic shock, the vibration signature changes, weeks or months before the breakage. Nothing visible to the eye, nothing audible: just a sensor curve whose texture has shifted. That shift is what the detector has to catch.

Why it is hard: three structural obstacles

If the problem were easy, an alarm threshold would do ("alert if temperature exceeds 80 °C"). Three obstacles say otherwise.

Anomalies are rare. That is their very definition. A well-maintained machine produces years of normal operation for a few hours of incident. So you cannot train an ordinary "normal versus abnormal" classifier: there are almost no examples of the second class.

Anomalies are unlabelled. Nobody annotated the historical data with "bearing drift starts here". And future failures will not necessarily resemble past ones: the next breakdown may be of a kind never observed. So you need methods that learn without labels, from normal behaviour alone.

"Abnormal" depends on context. Zero electricity consumption is perfectly normal at 3am, and deeply worrying at noon on a working day. A sales spike is normal on a Saturday in December, abnormal on a Tuesday in March. The same value, at the same point on the scale, is healthy or pathological depending on the moment. A fixed threshold is therefore blind: the model has to know the system's rhythms (see seasonality in the module overview).

Point, contextual and collective anomalies

The field's vocabulary distinguishes three forms. The point anomaly: a single impossible value (a sensor reporting −40 °C inside a furnace). The contextual anomaly: a value plausible in itself, but not at that moment (zero at noon). The collective anomaly: every point is normal, but their sequence is not (a heart beating at a correct rate but with perfect regularity, lacking natural variability, can be a clinical sign). The last two are invisible to a plain threshold.

Time series with two point anomalies labelled O1 and O2: O2 is an obvious isolated downward spike, while O1 only stands out in the zoom inset, as a value slightly off compared with its immediate neighbours.
Two point anomalies in the same series, taken from a survey of the field. O2 (right) is the easy case: an isolated spike any threshold would catch. O1 is only visible in the zoom: its value is unremarkable at the scale of the whole series, yet aberrant compared with its immediate neighbours, the contextual case, invisible to a fixed threshold.Source : Blázquez-García et al., A review on outlier/anomaly detection in time series data (via ar5iv)

The three families of methods

Almost everything in use falls into three families, from the simplest to the richest. All three share the same two-step logic: build a strangeness score (a number saying how far the present moment departs from normal), then alert when the score crosses a threshold.

1. Thresholds and statistics: deviation from the moving average

The historical approach: track the average of recent values (the moving average, which slides along with time) and the usual spread around it (the standard deviation, which measures the typical size of fluctuations). A point is suspicious if it strays from the average by much more than that usual spread:

scoret=∣xt−μt∣σt\text{score}_t = \frac{|x_t - \mu_t|}{\sigma_t}

where xtx_t is the value measured at time tt, μt\mu_t is the moving average of recent values and σt\sigma_t their standard deviation. In plain words: "by how many usual standard deviations does this point step out of the recent routine?". A score of 1 is unremarkable; a score of 5 deserves a look.

Simple, robust, widely used, and limited: this method only sees deviations of level. It misses contextual anomalies (the noon zero sits close to the 24-hour average) and collective ones (every point stays inside the band).

2. Forecast-based: the anomaly is a gap between forecast and reality

The second idea, and a very fertile one: take any forecasting model, have it predict the next moment, and compare with what actually happens. If reality departs sharply from the forecast, the system is no longer behaving the way its past suggested, a rather faithful definition of an anomaly. The strangeness score is simply the forecast error.

The elegance of this family is that it recycles the entire rest of the module: the forecasting model can be a classical statistical method (classical methods), a neural network (deep learning), a Transformer (Transformers for time series) or a pre-trained foundation model (foundation models). The better the forecast of normal, the sharper the detection of abnormal. And context comes for free: a good model forecasts "zero" at 3am and "a lot" at noon, so the noon zero produces a large error, the alert fires.

3. Reconstruction-based: what the model cannot redraw

Third idea: train an autoencoder (a network that compresses its input into a tiny summary, then tries to reconstruct it (the principle is covered in the autoencoders lesson)) on normal data only. The network becomes an excellent copyist of the normal: it has learned to redraw the patterns it has seen thousands of times. Faced with an abnormal stretch of curve it has never met, its copy is poor. The strangeness score is the reconstruction error: what the model reconstructs badly is abnormal.

The forger analogy: a copyist who has spent his life reproducing Rembrandts redraws them to perfection; ask him to reproduce a Cubist painting from memory, and the result will instantly betray that the style is foreign to him.

Periodic series with two abnormal subsequences labelled O1 and O2: O1 is an abnormally flat segment at the top of a cycle, O2 a sagging noisy segment, while every individual point stays within the usual range.
What this family can catch: whole abnormal shapes. In O1 the curve goes abnormally flat; in O2 it sags and turns noisy. No individual point leaves the normal range, it is the sequence that is abnormal, precisely what a copyist of the normal reconstructs badly.Source : Blázquez-García et al., A review on outlier/anomaly detection in time series data (via ar5iv)

Which family to choose?

FamilyWhat you need to be able to doStrengthLimit
Thresholds and statisticsAlmost nothing: an average, a standard deviationSimple, transparent, runs anywhereBlind to context and to collective anomalies
Forecast-basedForecast the normal wellHandles context for free; benefits from every advance in forecastingInherits the weaknesses of the chosen forecasting model
Reconstruction-basedCompress and reconstruct patternsCaptures whole abnormal shapes, not just point-by-point deviationsAn autoencoder that is too powerful reconstructs the abnormal too, it must be reined in

In practice, real systems often stack several layers: a cheap statistical threshold as the first line on the sensor, a richer model as the second line to sort the alerts.

From alert to action: alarm fatigue

A word on what happens after detection, because that is often where systems fail. An over-eager detector floods operators with alerts; after a few weeks, nobody reads them any more, this is alarm fatigue, well documented in hospitals and industrial control rooms alike. A strangeness score only has value if it reaches the right person, prioritised, with enough context to understand why the alert fired. The "presenting and sorting alerts" part of a system matters as much as the detection part, and it, too, is fertile ground for inventions.

A recent research example: the Anomaly Transformer

The Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy shows where research is heading. Its starting observation: inside a Transformer, you can inspect what each moment "pays attention to". A normal moment associates with points spread across the whole series (it resembles plenty of other moments, every Monday at 8am). An abnormal moment resembles nothing else: its attention falls back onto its immediate neighbours, for lack of anything better. The paper turns this gap between the two association profiles into the detection criterion itself, anomalies are the moments that only "know" their neighbours. A good example of an invention that comes not from a new architecture but from a new reading of what an existing architecture already computes.

The evaluation trap: 99.9% accuracy, zero detection

Here is the trap every newcomer to the field falls into, and one worth spotting in a disclosure.

Suppose 0.1% of the moments are abnormal, a realistic, even generous, proportion. A "detector" that always answers "everything is normal", without ever looking at anything, is right 999 times out of 1,000: 99.9% accuracy, zero anomalies detected. Accuracy (the percentage of correct answers) is a meaningless metric when one class crushes the other, exactly the class imbalance described in the evaluation metrics lesson.

The right questions are those of precision (of the alerts raised, how many were real anomalies? The mirror of the false-alarm rate) and recall (of the real anomalies, how many raised an alert? The mirror of the missed-failure rate). The two fight each other: lowering the alert threshold catches more failures but drowns operators in false alarms; raising it does the opposite. The right setting is an economic decision, cost of a false alarm versus cost of a missed failure, not a purely technical one.

Two time-specific nuances follow. First, detection delay: catching the bearing's drift two days late is excellent (the breakdown is a month away); catching the fraud two days late may be useless (the money is gone). The same numerical performance is worth very different amounts depending on the use. Second, labels do eventually arrive: every confirmed breakdown, every proven fraud becomes an annotated example. Mature systems close this loop, yesterday's confirmed incidents are used to recalibrate tomorrow's detector.

A reading reflex for detection announcements

An anomaly-detection disclosure that proudly announces "99% accuracy" without giving precision and recall demonstrates nothing at all. Demanding those two numbers (and the proportion of anomalies in the test data) is the first check to run.

A word on deployment: these models live at the edge

One last peculiarity, heavy with technical consequences: these models often run on the sensor itself or very close to it, what is called edge computing (processing at the "edge" of the network, as opposed to a distant data centre).

The reasons are concrete. A factory has thousands of sensors measuring several times a second: shipping that whole stream to a remote server is expensive in bandwidth, adds a round-trip delay incompatible with an emergency stop, depends on a connection that can drop, and sends sometimes-sensitive data out of the plant. The solution: a small model housed in the sensor's casing or in a workshop gateway, filtering locally and sending up only the alerts.

The consequence: anomaly detection is one of the domains where model compression matters most, models deliberately tiny, quantised, tailored to a modest processor and a few milliwatts. An amusing reversal: while forecasting races towards giant foundation models, anomaly detection pushes in the opposite direction. Both movements are fertile ground for inventions, and embedded-implementation tricks (what to compute locally, what to send upstream, how to update the model remotely) are a steady source of them.

The same concern for keeping data in place leads naturally to federated learning: training a shared model across several sites (several factories, several hospitals) without the raw data ever leaving each site, only the model's adjustments travel. The federated learning lesson covers this mechanism, widely used in exactly the industrial and medical settings this page is about.

Key points

  1. The principle: learn a system's normal behaviour to spot departures from it, because failures, fraud and incidents are too rare and too varied to be learned directly.
  2. Three obstacles: anomalies are rare (no "abnormal" class to learn), unlabelled (nobody annotated the drifts), and contextual (zero is normal at night, alarming at noon, a fixed threshold is blind).
  3. Three families: statistical (deviation from the moving average (simple but context-blind), forecast-based (the anomaly is a gap from the forecast) recycles every model in the module), reconstruction-based (an autoencoder trained on normal data reconstructs the abnormal poorly).
  4. The Anomaly Transformer detects moments whose attention collapses onto their immediate neighbours, an invention born of a new reading of existing computations.
  5. The evaluation trap: with 0.1% anomalies, 99.9% accuracy detects nothing. Demand precision (false alarms) and recall (missed failures); their balance is an economic decision.
  6. After the detection: detection delay matters as much as the rate (two days late is excellent for wear, useless for fraud), and a system that drowns its operators in alerts fails through alarm fatigue.
  7. Edge deployment: these models often run on or near the sensor, so they must be small, against the current of the race to giant models, and rich in implementation inventions.
Check your understanding0 / 5

1. Why not simply train a 'normal versus abnormal' classifier on a machine's history?

2. Electricity consumption drops to zero at midday on a working day. Why might the moving-average deviation method flag nothing?

3. An autoencoder trained only on normal data is used as a detector. What is the mechanism, and what is its specific weakness?

4. A filing announces '99.9% accuracy' for an anomaly detector. What should be demanded, and why?

5. Why do these models often run on the sensor itself rather than in a distant data centre?