milia.anomaly.models.hbos#

HBOS: histogram-based outlier score.

Classes

HBOS([bins, alpha, contamination])

Per-dimension histogram detector (Goldstein and Dengel, 2012).

HBOSConfig(*[, name, kind, space, bins, ...])

Validated hyperparameters of the HBOS detector.

class milia.anomaly.models.hbos.HBOS(bins=10, alpha=0.1, contamination=0.1)#

Bases: BaseDetector

Per-dimension histogram detector (Goldstein and Dengel, 2012).

Each feature gets a static-width histogram, normalised so its tallest bin is one. A point’s score is the sum over features of -log(height + alpha), where values outside the training range fall in an empty bin.

Parameters:
  • bins (int) – Bins per feature.

  • alpha (float) – Regulariser added to every bin height, avoiding log(0).

  • contamination (float) – Expected share of outliers, used for the default threshold.

Examples

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> train, cal = rng.normal(size=(200, 2)), rng.normal(size=(100, 2))
>>> model = HBOS().fit(train).calibrate(cal, alpha=0.1)
>>> model.flag(np.array([[0.0, 0.0], [8.0, 8.0]])).tolist()
[False, True]
class milia.anomaly.models.hbos.HBOSConfig(*, name='hbos', kind='detector', space=SearchSpace(bins=(5, 50)), bins=10, alpha=0.1, contamination=0.1)#

Bases: BaseModelConfig

Validated hyperparameters of the HBOS detector.

Fields mirror HBOS’s constructor; space is the default Optuna search space. Build the detector with make("detector", "hbos", ...) or HBOS(**config.params()).

Examples

>>> HBOSConfig().name
'hbos'