milia.anomaly.models.lof#

Local Outlier Factor: local density relative to a point’s own neighbours.

Classes

LOF([n_neighbors, metric, contamination])

Local density detector (Breunig et al., 2000), in novelty mode.

LOFConfig(*[, name, kind, space, ...])

Validated hyperparameters of the Local Outlier Factor detector.

class milia.anomaly.models.lof.LOF(n_neighbors=20, metric='minkowski', contamination=0.1)#

Bases: BaseDetector

Local density detector (Breunig et al., 2000), in novelty mode.

Parameters:
  • n_neighbors (int) – Neighbourhood size for the local density estimate.

  • metric (str) – Distance metric.

  • 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 = LOF().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.lof.LOFConfig(*, name='lof', kind='detector', space=SearchSpace(n_neighbors=(5, 100)), n_neighbors=20, metric='minkowski', contamination=0.1)#

Bases: BaseModelConfig

Validated hyperparameters of the Local Outlier Factor detector.

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

Examples

>>> LOFConfig().name
'lof'