Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.One histogram per feature
For each measurement separately, count how often each range of values occurs: a histogram. A value from a rarely-visited range is a little suspicious. HBOS does this for every feature, then adds up the suspicion across features. A point that is a bit unusual in several features, or very unusual in one, gets a high score. It is fast and easy to explain. But because it looks at each feature on its own, it cannot notice a point whose values are individually ordinary but never occur together.
Telemetry streams can have hundreds of channels and millions of samples. HBOS processes them in a single pass per channel, and its score can be broken down by channel (“this sample is odd mostly because of channel 37”), which operators like. Knowing that it ignores correlations tells you when to pair it with a multivariate method.
- 1. HBOS builds…
- 2. HBOS assumes the features are…
- 3. A point that breaks a strong correlation but has ordinary values in each feature is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Bins, heights and the score by hand
Static (equal-width) bins. Split each feature’s range into k bins of equal width. The square-root rule gives k ≈ √n: 44 bins for n = 2020.
Dynamic (equal-frequency) bins. Put bin edges at quantiles, so each bin holds about n/k points. For 1 … 100 with k = 4, the edges are 1, 25.75, 50.5, 75.25 and 100. Bin height is count divided by width, so wide tail bins have low height.
Normalisation. Divide each feature’s bin densities by its tallest bin, so heights lie in (0, 1]. Counts 10, 5, 1 in equal-width bins give heights 1, 0.5 and 0.1.
Score. HBOS(p) = Σ_features log(1/h_f(p)), with h_f(p) the normalised height of p’s bin in feature f.
- A point in the tallest bin of every feature scores 0.
- Heights 0.5 and 0.25 give log 2 + log 4 = log 8 = 2.08.
Since log(1/h) sums over features, HBOS is the negative log of the product of per-feature densities: the joint density if the features were independent.
The steps in plain English:
- For each feature, build a histogram (static, or dynamic for long tails and gaps) with about √n bins; give categorical features one bin per category.
- Normalise each histogram so its tallest bin has height 1.
- Score each point by Σ log(1/height), using a small floor for empty bins.
- Rank or threshold the scores, and report each feature’s contribution for explanation.
- 1. Equal-frequency bins put edges at…
- 2. A point in every feature's tallest bin scores…
- 3. HBOS is the negative log of…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.What independence costs
Cost. Building the histograms is O(n d) for static bins, or O(n d log n) with the sorting needed for dynamic bins. Scoring is O(d) per point. There are no distances and no pairwise computations, so HBOS is among the fastest detectors.
The independence assumption. If features are correlated, the true joint density is concentrated along the correlation, while the product of marginals spreads it over a rectangle. A point off the correlation axis but inside both marginal ranges gets an ordinary HBOS score, however impossible the combination.
Static versus dynamic bins. Static bins have a resolution set by the range, so one extreme value can squash all normal data into a few bins. Dynamic bins adapt to the data but make tail bins wide, which dilutes the low density of rare tail values: every bin holds n/k points by construction.
Exercise 1 (2020 points in 10-D, each anomaly extreme (±5) in one random feature):
- AUC 0.909 with static bins and 0.821 with dynamic bins;
- 44 bins per feature, scored in about a millisecond;
- the other nine ordinary features add noise to each anomaly’s summed score.
from pyod.models.hbos import HBOS # PyOD's implementation
s = HBOS(n_bins="auto").fit(X).decision_scores_- 1. HBOS scoring costs per point about…
- 2. Dynamic bins weaken tail detection because…
- 3. For correlated features, the product of marginals spreads density over…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Probabilistic reading. With normalised heights hᶠ = f̂ᶠ/max f̂ᶠ, HBOS(p) = −Σ log f̂ᶠ(pᶠ) + constant, the naive-Bayes negative log-likelihood of p under independent marginals. Ranking by HBOS is equivalent to ranking by that likelihood. Like naive Bayes, it can rank well when dependence is weak or symmetric, and fail badly when anomalies live in the dependence structure.
Bin count. Histogram density estimates trade bias (wide bins) against variance (narrow bins). The optimal width for density estimation shrinks like n^(−1/3) (Scott; Freedman–Diaconis). The √n rule is a looser heuristic. Too many bins create empty bins inside the normal range, which act as false holes.
Fixes for dependence. Decorrelate first, with PCA or whitening on clean data, then apply HBOS to the components. Use LODA (Pevný, 2016), an ensemble of histograms on random one-dimensional projections that keeps HBOS’s speed while seeing combinations. Or fall back to multivariate detectors.
Interview questions.
- Why is HBOS popular despite its naive assumption? It is fast, streamable, explainable per feature, and in benchmarks (Goldstein and Uchida, 2016) competitive on many real datasets with global anomalies.
- When should you not use HBOS? When anomalies are defined by relationships between variables, such as sensor consistency or physical laws coupling channels, and when local anomalies within clusters matter.
- 1. Ranking by HBOS equals ranking by…
- 2. LODA extends HBOS by using histograms on…
- 3. Too many bins cause…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Where independence breaks
History.
- M. Goldstein and A. Dengel (2012) introduced HBOS.
- M. Goldstein and S. Uchida (2016) benchmarked unsupervised detectors, with HBOS competitive on global anomalies.
- T. Pevný (2016) introduced LODA, random-projection histograms.
- PyOD (Zhao et al., 2019) made HBOS a standard baseline.
Exercise 2. 1500 normal points plus 20 anomalies, 3 datasets of each kind. The table gives AUC.
| anomalies… | HBOS static | HBOS dynamic | Mahalanobis |
|---|---|---|---|
| extreme in one feature (5-D, ±5σ) | 0.976 | 0.913 | 0.994 |
| breaking a correlation (2-D, ρ = 0.95) | 0.592 | 0.569 | 0.999 |
| rare values in heavy-tailed (lognormal) features | 0.942 | 0.904 | 0.993 |
- HBOS was close to chance on correlation-breaking anomalies (0.59) while Mahalanobis distance found them perfectly. Each anomaly’s coordinates were ordinary on their own; only the combination was impossible.
- Static bins beat dynamic bins in all three cases. The equal-frequency tail bins gave rare values the same mass as everyone else in their bin.
- For marginal anomalies HBOS worked well (0.976), close to Mahalanobis, at a fraction of the cost.
- Here even the heavy-tailed data favoured Mahalanobis, because the anomalies were placed at extreme quantiles that also have large Mahalanobis distance. HBOS’s real advantages are speed, scale and per-feature explanations, not accuracy on these synthetic cases.
HBOS in AI, robotics and aerospace
- High-rate telemetry screening: score each frame across hundreds of channels in microseconds, with per-channel contributions for the operator.
- Log and event data: categorical features (message types, codes) fit naturally as one bin per category.
- First-pass filtering: HBOS for a fast global screen, followed by a multivariate check (robust Mahalanobis, Isolation Forest) on the candidates.
References
- M. Goldstein, A. Dengel (2012). “Histogram-based outlier score (HBOS): a fast unsupervised anomaly detection algorithm.” KI-2012: Poster and Demo Track.
- M. Goldstein, S. Uchida (2016). “A comparative evaluation of unsupervised anomaly detection algorithms for multivariate data.” PLoS ONE 11(4).
- T. Pevný (2016). “Loda: lightweight on-line detector of anomalies.” Machine Learning 102(2).
- Y. Zhao, Z. Nasrullah, Z. Li (2019). “PyOD: a Python toolbox for scalable outlier detection.” Journal of Machine Learning Research 20.