Skip to content

Model

fyt.registries.model

ModelRegistry

Bases: ComponentRegistry[BaseEstimator]

Registry for machine learning model types.

Note

The ModelRegistry is designed to manage the creation of machine learning model instances based on string identifiers. It includes special handling for ensemble models like VotingClassifier and StackingClassifier.

In case you want to use a different ensemble model, you can register it with a custom factory function that handles the creation logic, similar to how VotingClassifier and StackingClassifier are handled in this registry.

create(key, **kwargs) classmethod

Create a model, handling ensemble types specially.

Parameters:

Name Type Description Default
key str | Enum

Model type identifier.

required
**kwargs Any

Model parameters.

{}

Returns:

Type Description
BaseEstimator

A scikit-learn compatible model instance.

Raises:

Type Description
ValueError

If the model type is not registered.

create_estimators(estimators_list, random_state=None) classmethod

Create a list of estimators for ensemble models.

Duplicate model types are given unique names by suffixing the ordinal occurrence (e.g. random_forest, random_forest_2, ...).

Parameters:

Name Type Description Default
estimators_list list[Estimator]

List of estimator configurations.

required
random_state int | None

Random state forwarded to each base estimator that accepts it, unless the estimator's own parameters already set it.

None

Returns:

Type Description
list[tuple[str, BaseEstimator]]

List of (name, estimator) tuples with unique names.

Raises:

Type Description
ValueError

If a nested ensemble model is specified.

create_seeded(model_type, params, random_state)

Create a model, injecting random_state when the estimator accepts it.

Parameters:

Name Type Description Default
model_type str | Enum

Model type identifier.

required
params dict[str, Any]

Model parameters. An explicit random_state here takes precedence over the random_state argument.

required
random_state int

Random state injected when params does not set one.

required

Returns:

Type Description
BaseEstimator

A scikit-learn compatible model instance.

Raises:

Type Description
TypeError

If random_state was explicitly set in params but the estimator does not accept it.