Clustering, density estimation, and anomaly detection · Anomaly detection · UCL055 · Algorithm
Histogram-Based Outlier Score (HBOS)
Build a fast tabular anomaly baseline from independent feature histograms. It is useful for large datasets where transparent marginal rarity is more important than complex dependence modeling.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page.
- ECOD anomaly scores Verified in Python and R
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Runs in CodeSplash
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through discover.ecod. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Build a fast tabular anomaly baseline from independent feature histograms. It is useful for large datasets where transparent marginal rarity is more important than complex dependence modeling.
Question / hypotheses
Which observations deviate from the chosen reference notion of normality, and at what operational alert rate? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.
Architecture / computational structure
Independent feature histograms and summed negative log-density contributions.
Assumptions
The independence approximation can miss anomalous combinations whose individual feature values are ordinary. Conversely, many correlated features can repeatedly count the same evidence. Categorical frequency tables require their own interpretation.
Formula / computational definition
A basic score is , where is the estimated histogram density for feature . Bin width matters for continuous-density normalization; smoothing or a positive floor prevents infinite scores in empty bins.
Parameters and notation
Learned or fitted quantities: Bin boundaries, density estimates, and threshold. User-set hyperparameters/design choices: Choose binning strategy, bin count, density floor, and handling outside the observed range. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.
Fitting, fine-tuning, and adaptation
Neural fine-tuning is not applicable to this classical detector. Refit the reference model when its population changes, then recalibrate an alert threshold on a separate normal holdout. Tune sensitivity without using final-test anomaly labels repeatedly.
How to use and calibrate
Inspect per-feature contributions and sensitivity to bin edges, compare with dependence-aware detectors, and calibrate thresholds on separate reference data. Report false-alarm concentration in tails or minority subgroups.
Example application
Build an interpretable high-volume marginal anomaly screen. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.
Interpretation / pitfalls
Watch out
The reported result is conditional on the representation and objective. An alert is a screening result, not a diagnosis or a calibrated posterior probability. Evaluate both ranking and the decision threshold.
Python and R code examples
PyOD supplies HBOS. Native R can combine hist(..., plot=FALSE) with explicit bin lookup and smoothing. The paired component aggregates supplied positive marginal densities; complete fitting additionally needs consistent training bins and new-data lookup rules.
Component: HBOS marginal surprise aggregation. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — HBOS marginal surprise aggregation. · needs numpy
import numpy as np
density=np.array([[.5,.2],[.01,.1],[.4,.3]]); floor=1e-10
result=-np.log(np.maximum(density,floor)).sum(1)
print(result)
Component demo, not a trained model — HBOS marginal surprise aggregation.
density=rbind(c(.5,.2),c(.01,.1),c(.4,.3)); floor=1e-10
result=-rowSums(log(pmax(density,floor)))
print(result)
Sources
- Source 1pyod.readthedocs.io
From the CodeSplash reference, entry UCL055.