milia.core.registry#

Registry of detectors and clusterers.

A model registers by living in its kind’s models package, one module per model: milia/anomaly/models/iforest.py for the detector "iforest", milia/cluster/models/kmeans.py for the clusterer "kmeans". The module defines exactly one estimator (a subclass of the kind’s base class) and one config (a subclass of BaseModelConfig); the registry finds both by subclass, so no decorator or naming rule is needed.

Modules are imported lazily, so asking for one model never imports another model’s optional dependency.

Functions

available(kind)

Names of every registered model of a kind, installed extras or not.

base(kind)

The estimator base class for a kind of model.

clusterer(name)

Shorthand for get("clusterer", name).

detector(name)

Shorthand for get("detector", name).

get(kind, name)

Look up a model's estimator and config classes.

make(kind, name[, config])

Build an unfitted estimator from its config.

milia.core.registry.base(kind)#

The estimator base class for a kind of model.

Parameters:

kind (Literal['detector', 'clusterer']) – "detector" or "clusterer".

Return type:

type

Returns:

BaseDetector or BaseClusterer.

Raises:

ConfigurationError – If kind is unknown.

Examples

>>> base("detector").__name__
'BaseDetector'
milia.core.registry.available(kind)#

Names of every registered model of a kind, installed extras or not.

Parameters:

kind (Literal['detector', 'clusterer']) – "detector" or "clusterer".

Return type:

list[str]

Returns:

Sorted registry names.

Examples

>>> available("detector")
['controllimit', 'copod', 'ecod', 'hbos', 'iforest', 'kde', 'knn', 'lof', 'mahalanobis', 'ocsvm',
 'reconstruction']
milia.core.registry.get(kind, name)#

Look up a model’s estimator and config classes.

The model’s module is imported on first use and the pair cached.

Parameters:
  • kind (Literal['detector', 'clusterer']) – "detector" or "clusterer".

  • name (str) – Registry name, e.g. "iforest".

Return type:

tuple[type, type[BaseModelConfig]]

Returns:

(estimator class, config class).

Raises:

Examples

>>> estimator, config = get("clusterer", "kmeans")
>>> estimator.__name__, config.__name__
('KMeans', 'KMeansConfig')
milia.core.registry.detector(name)#

Shorthand for get("detector", name).

Parameters:

name (str) – Registry name of the detector.

Return type:

tuple[type, type[BaseModelConfig]]

Returns:

(estimator class, config class).

Examples

>>> detector("lof")[0].__name__
'LOF'
milia.core.registry.clusterer(name)#

Shorthand for get("clusterer", name).

Parameters:

name (str) – Registry name of the clusterer.

Return type:

tuple[type, type[BaseModelConfig]]

Returns:

(estimator class, config class).

Examples

>>> clusterer("hdbscan")[0].__name__
'HDBSCAN'
milia.core.registry.make(kind, name, config=None, **overrides)#

Build an unfitted estimator from its config.

Parameters:
  • kind (Literal['detector', 'clusterer']) – "detector" or "clusterer".

  • name (str) – Registry name.

  • config (BaseModelConfig | None) – A config instance; the default config when omitted.

  • **overrides (Any) – Hyperparameters that replace the config’s values.

Return type:

Any

Returns:

The estimator instance.

Examples

>>> make("detector", "iforest", n_estimators=50).n_estimators
50