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
Fields that describe the config itself and never reach the estimator. |
Classes
|
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:
BaseModelHyperparameters for one registered estimator.
Subclasses fix
nameandkindand 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,kindandspaceare left out, so the result can be passed straight to the estimator.Examples
>>> from milia import get >>> _, config = get("detector", "lof") >>> config(n_neighbors=10).params() {'n_neighbors': 10, 'metric': 'minkowski', 'contamination': 0.1}