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
|
Names of every registered model of a kind, installed extras or not. |
|
The estimator base class for a kind of model. |
|
Shorthand for |
|
Shorthand for |
|
Look up a model's estimator and config classes. |
|
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:
- Returns:
- Raises:
ConfigurationError – If
kindis 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:
- 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:
- Return type:
- Returns:
(estimator class, config class).- Raises:
MissingExtraError – If the model needs an extra that is not installed.
ConfigurationError – If no such model exists.
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:
- 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:
- 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:
- Returns:
The estimator instance.
Examples
>>> make("detector", "iforest", n_estimators=50).n_estimators 50