CAB206 · Unit 5: AI for business intelligence
Anomaly detection
9 practice questions
Key points
- Point, contextual and collective anomalies
- Z-score rule 3 sigma; small n cannot reach z of 3
- IQR fences at 1.5 x IQR; robust z uses median and MAD
- Isolation Forest isolates anomalies in fewer splits
- False alarms scale with the number of metrics monitored
An anomaly (outlier) is an observation that deviates markedly from the rest. In business it signals fraud, system faults, data-entry errors, or genuine events such as a viral sale.
Types: point anomaly (one unusual value), contextual anomaly (normal in one context, unusual in another: 5,000 sales on a regular Tuesday vs during a festival), collective anomaly (a sequence that is odd together).
Statistical methods
- Z-score: z = (x - mean) / sd; flag |z| above 3 (a common rule). It assumes roughly normal data. Outliers inflate the mean and sd and can mask themselves. With n values, the largest possible |z| (using sample sd) is (n - 1) / sqrt(n), so with n = 9 it is only 2.67 and a 3-sigma rule can never fire.
- IQR rule: flag values below Q1 - 1.5 x IQR or above Q3 + 1.5 x IQR (the box-plot whiskers). For 2, 4, 4, 5, 6, 7, 8, 9, 30 (linear-interpolation quartiles, the NumPy and pandas default) Q1 = 4, Q3 = 8, IQR = 4, fences -2 and 14, so 30 is flagged.
- Robust z-score (median and MAD): modified z = 0.6745 x (x - median) / MAD, flag above 3.5. Here median = 6, MAD = 2, and 30 scores 8.09. Median and MAD are not distorted by the outlier.
Machine-learning methods: Isolation Forest isolates points with random splits; anomalies are separated in fewer splits (shorter path) and get lower scores. Local Outlier Factor and DBSCAN use density. Autoencoders flag records with large reconstruction error.
Operating it. Every threshold trades false alarms for misses. At a 1% false-positive rate across 1,000 monitored metrics you expect about 10 false alarms a day, which causes alert fatigue. Investigate flagged values: they may be errors to fix, not events to celebrate.
Try two questions
An Isolation Forest scores a point as anomalous when it:
- Appears at least twice in the data used to train the model
- Is the largest value found in every column of the table
- Has the highest frequency of occurrence in the whole dataset
- Is separated from the rest in fewer random splits
Show the answer
D. Anomalies are few and different, so random splits isolate them quickly; their average path length is short.
A sale of 5,000 is normal during a festival week but unusual on a regular Tuesday. This is a:
- Contextual anomaly
- Point anomaly in every context
- Collective anomaly only
- Data-type error
Show the answer
A. A value that is unusual only in a particular context (time, place) is a contextual anomaly.