Models
Available models
The algorithm setting of a model is the name of an estimator class. ModelRegistry resolves the name by first checking the models registered with it, then searching these modules in order:
| Module | Examples |
|---|---|
sklearn.ensemble |
HistGradientBoostingClassifier, RandomForestClassifier |
sklearn.linear_model |
LogisticRegression |
sklearn.isotonic |
IsotonicRegression |
ngboost |
NGBRegressor |
ordboost |
OrdBoostClassifier, OrdBoostRegressor |
The name must match the class name exactly. The hyperparameters setting is passed to the class constructor.
Adding a model
Decorate an estimator class with ModelRegistry.register. The decorator takes the name to register the class under, which defaults to the class name. The model can then be used by name in the configuration file.
from sklearn.ensemble import RandomForestClassifier
from medpipe import ModelRegistry
@ModelRegistry.register("ShallowForest")
class ShallowForest(RandomForestClassifier):
def __init__(self, n_estimators=100, max_depth=3, random_state=None):
super().__init__(
n_estimators=n_estimators,
max_depth=max_depth,
random_state=random_state,
)
Register the model before creating the pipeline, so that the configuration is validated against it.
A complete script that registers a model, a preprocessing operation and a metric is shown in the examples.
registry
ModelRegistry
Bases: BaseRegistry[type[BaseEstimator]]
Registry for managing and resolving machine learning estimators.