milia.anomaly.models.kde#

Kernel density estimate: how far into a low-density region a point sits.

Classes

KDE([bandwidth, kernel, contamination])

Density detector: negative log-density under a kernel density estimate.

KDEConfig(*[, name, kind, space, bandwidth, ...])

Validated hyperparameters of the kernel density detector.

class milia.anomaly.models.kde.KDE(bandwidth=1.0, kernel='gaussian', contamination=0.1)#

Bases: BaseDetector

Density detector: negative log-density under a kernel density estimate.

Parameters:

Examples

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> train, cal = rng.normal(size=(200, 2)), rng.normal(size=(100, 2))
>>> model = KDE().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.kde.KDEConfig(*, name='kde', kind='detector', space=SearchSpace(bandwidth=(0.05, 5.0)), bandwidth=1.0, kernel='gaussian', contamination=0.1)#

Bases: BaseModelConfig

Validated hyperparameters of the kernel density detector.

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

Examples

>>> KDEConfig().name
'kde'