milia.anomaly.models.kde#
Kernel density estimate: how far into a low-density region a point sits.
Classes
|
Density detector: negative log-density under a kernel density estimate. |
|
Validated hyperparameters of the kernel density detector. |
- class milia.anomaly.models.kde.KDE(bandwidth=1.0, kernel='gaussian', contamination=0.1)#
Bases:
BaseDetectorDensity detector: negative log-density under a kernel density estimate.
- Parameters:
bandwidth (
float|str) – Kernel bandwidth, or"scott"/"silverman".kernel (
str) – Kernel name, as insklearn.neighbors.KernelDensity.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 = 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:
BaseModelConfigValidated hyperparameters of the kernel density detector.
Fields mirror
KDE’s constructor;spaceis the default Optuna search space. Build the detector withmake("detector", "kde", ...)orKDE(**config.params()).Examples
>>> KDEConfig().name 'kde'