liveBook · Manning

Contextual anomaly

As explained in Outlier Detection in Python

A contextual outlier is an observation that is anomalous only relative to its temporal or contextual conditions.

A contextual anomaly is a value that appears normal across the full dataset but becomes unusual under its temporal or situational conditions. The context may include nearby observations, previous readings, trends, cycles, or readings from other sensors. This distinguishes contextual anomalies from point anomalies, which are unusual in isolation. section 1.1.5 section 17.2.2

Detect contextual anomalies by choosing and interpreting an appropriate reference context:

  • Compare offline observations with points immediately before and after them; streaming systems generally compare only with preceding data. section 17.2.2
  • Choose a reference window carefully: looking too far back can hide a local anomaly, while looking too briefly can make comparison unreliable. section 17.2.2
  • Check changes as well as absolute values, since a sudden vibration increase may be anomalous even when its level remains within the normal range. section 17.2.2
  • Compare sensors for unusual combinations or associations, and monitor repeated or escalating anomalies rather than treating every isolated alert as equally important. section 1.1.5

A local spike in equipment data

An equipment reading at 120 seconds rises by about 200 points relative to its neighbors. Its absolute value is normal across the full series, but the immediate spike is anomalous in context. A smoothed reference line can provide a more stable comparison than the raw neighboring values. section 17.2.2

Figure 17.3 Example of contextual point outlier. The x-axis indicates time values in seconds. The point indicated with a dot at 120 seconds is unusual considering the context of its immediate neighborhood of values, though it has a normal value considering the full range of data shown.

Inspect the time-series example where a normal-range value becomes anomalous because of its immediate neighborhood. section 17.2.2

How Outlier Detection in Python covers it

How deep it goes
Explains reference windows, local changes, spikes, smoothing, and cross-sensor comparisons, while deferring detailed algorithmic methods.
Examples
Uses industrial sensors, vibration changes, a 120-second time-series spike, and smoothed reference values.
What it assumes
Assumes familiarity with readings and time-series order, while introducing contextual comparison from basic point-anomaly distinctions.
What you can do after
Diagnose context-dependent readings by selecting comparison windows, checking local changes, and interpreting sensor relationships.
How it connects
Links contextual anomalies with point anomalies, collective anomalies, multivariate time series, smoothing, and forecasting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.