milia.core.config.base#

Base configuration shared by every registered estimator.

A config holds an estimator’s hyperparameters as a validated pydantic model. The estimator itself is a plain scikit-learn estimator with keyword hyperparameters; the config builds it (Estimator(**config.params())) and supplies Optuna’s search space for tuning (config.sample(trial)).

Module Attributes

META

Fields that describe the config itself and never reach the estimator.

Classes

BaseModelConfig(*[, name, kind, space])

Hyperparameters for one registered estimator.

milia.core.config.base.META = frozenset({'kind', 'name', 'space'})#

Fields that describe the config itself and never reach the estimator.

class milia.core.config.base.BaseModelConfig(*, name='base', kind='base', space=None)#

Bases: BaseModel

Hyperparameters for one registered estimator.

Subclasses fix name and kind and declare the estimator’s hyperparameters as fields, with the same names as the estimator’s constructor arguments:

class IForestConfig(BaseModelConfig):
    name: Literal["iforest"] = Field("iforest", exclude=True)
    kind: Literal["detector"] = Field("detector", exclude=True)
    n_estimators: int = 100
    space: SearchSpace | None = Field(SearchSpace(n_estimators=(50, 500)), exclude=True)
Parameters:
  • name (str) – Registry name of the estimator. Fixed per subclass.

  • kind (str) – "detector" or "clusterer". Fixed per subclass.

  • space (SearchSpace | None) – Optional hyperparameter search space for tuning.

Examples

>>> from milia import get
>>> estimator, config = get("detector", "knn")
>>> settings = config(n_neighbors=7)
>>> estimator(**settings.params()).n_neighbors
7
params()#

The estimator’s constructor keyword arguments.

The descriptive fields name, kind and space are left out, so the result can be passed straight to the estimator.

Return type:

dict[str, Any]

Returns:

Hyperparameter name to value.

Examples

>>> from milia import get
>>> _, config = get("detector", "lof")
>>> config(n_neighbors=10).params()
{'n_neighbors': 10, 'metric': 'minkowski', 'contamination': 0.1}
sample(trial)#

Fixed hyperparameters overridden by values sampled from space.

Parameters:

trial (Trial) – The active Optuna trial.

Return type:

dict[str, Any]

Returns:

Constructor keyword arguments for this trial.