milia.anomaly.models.ocsvm#

One-class SVM: distance from a learned support boundary.

Classes

OCSVM([kernel, nu, gamma, contamination])

Boundary detector (Schölkopf et al., 2001).

OCSVMConfig(*[, name, kind, space, kernel, ...])

Validated hyperparameters of the one-class SVM detector.

class milia.anomaly.models.ocsvm.OCSVM(kernel='rbf', nu=0.5, gamma='scale', contamination=0.1)#

Bases: BaseDetector

Boundary detector (Schölkopf et al., 2001).

Parameters:
  • kernel (str) – Kernel name.

  • nu (float) – Upper bound on the training-error fraction.

  • gamma (float | str) – Kernel coefficient.

  • 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 = OCSVM().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.ocsvm.OCSVMConfig(*, name='ocsvm', kind='detector', space=SearchSpace(nu=(0.01, 0.5)), kernel='rbf', nu=0.5, gamma='scale', contamination=0.1)#

Bases: BaseModelConfig

Validated hyperparameters of the one-class SVM detector.

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

Examples

>>> OCSVMConfig().name
'ocsvm'