Skip to content

Models and Registry API

See the Custom Models and Search Spaces guide for usage.

make_classifier

h2ml.core.step.make_classifier(estimator, name=None, requires_scaling=False)

Shorthand for wrapping a sklearn classifier.

Examples:

>>> from sklearn.svm import SVC
>>> step = make_classifier(SVC(), requires_scaling=True)

make_regressor

h2ml.core.step.make_regressor(estimator, name=None, requires_scaling=False)

Shorthand for wrapping a sklearn regressor.

Examples:

>>> from sklearn.linear_model import Ridge
>>> step = make_regressor(Ridge(), requires_scaling=True)

ModelWrapper

h2ml.core.step.ModelWrapper

Bases: BaseClassifier, BaseRegressor

Wraps any sklearn-compatible classifier or regressor into a BaseStep.

Parameters:

Name Type Description Default
estimator Any

A fitted or unfitted sklearn estimator.

required
name Optional[str]

Optional display name. Defaults to class name.

None
requires_scaling bool

Whether this model needs StandardScaler applied before fitting. The CV engine reads this flag.

False
verbose bool

Print fit/predict progress.

False

Examples:

>>> from sklearn.ensemble import RandomForestClassifier
>>> step = ModelWrapper(RandomForestClassifier(n_estimators=100))
>>> step.fit(X_train, y_train)
>>> preds = step.predict(X_test)

predict_proba(X)

Returns class probabilities. Only valid for classifiers. Raises clearly if called on a regressor or uncalibrated model.

transform(X)

Pass-through for classifiers and regressors. For transformers (preprocessors), delegates to estimator.transform().

ModelEntry

h2ml.utils.registry.ModelEntry dataclass

Unified descriptor for a single model in the h2ml registry.

Attributes:

Name Type Description
model_cls type

Sklearn estimator class.

default_kwargs dict

Constructor args for the default (non-optimized) instance.

requires_scaling bool

Whether StandardScaler must be applied before fitting.

param_fn Optional[Callable]

Optuna trial function returning a hyperparameter dict. None means optimization is disabled for this model.

opt_enabled bool

Set False to exclude from optimization even if param_fn exists.

supports_class_weight bool

Whether the estimator accepts class_weight="balanced". When True, PipelineConfig.handle_imbalance can inject it.

build_model()

Instantiate a ModelWrapper with default kwargs and scaling flag.

build_models

h2ml.utils.registry.build_models(task)

Build a ModelWrapper list from the registry for a given task.

Parameters:

Name Type Description Default
task str

'classification' or 'regression'.

required

Returns:

Type Description
list['ModelWrapper']

List of ModelWrapper instances with correct scaling flags and default kwargs.