MultiQuantileRegressor#

class openstef_models.utils.multi_quantile_regressor.MultiQuantileRegressor(base_learner: type[BaseEstimator], quantile_param: str, quantiles: list[float], hyperparams: dict[str, float | int | str | bool | None])[source]

Bases: BaseEstimator, RegressorMixin

Adaptor for multi-quantile regression using a base quantile regressor.

This class creates separate instances of a given quantile regressor for each quantile and manages their training and prediction.

Parameters:
__init__(base_learner: type[BaseEstimator], quantile_param: str, quantiles: list[float], hyperparams: dict[str, float | int | str | bool | None])[source]

Initialize MultiQuantileRegressor.

This is an adaptor that allows any quantile-capable regressor to predict multiple quantiles by instantiating separate models for each quantile.

Parameters:
  • base_learner (type[BaseEstimator]) – A scikit-learn compatible regressor class that supports quantile regression.

  • quantile_param (str) – The name of the parameter in base_learner that sets the quantile level.

  • quantiles (list[float]) – List of quantiles to predict (e.g., [0.1, 0.5, 0.9]).

  • hyperparams (dict[str, float | int | str | bool | None]) – Dictionary of hyperparameters to pass to each estimator instance.

  • base_learner

  • quantile_param

  • quantiles

  • hyperparams

fit(X: ndarray[tuple[Any, ...], dtype[floating]] | DataFrame, y: ndarray[tuple[Any, ...], dtype[floating]] | Series, sample_weight: ndarray[tuple[Any, ...], dtype[floating]] | Series | None = None, feature_name: list[str] | None = None, eval_set: list[tuple[DataFrame, ndarray[tuple[Any, ...], dtype[floating]]]] | None = None, eval_sample_weight: list[ndarray[tuple[Any, ...], dtype[floating]]] | list[Series] | None = None) None[source]

Fit the multi-quantile regressor.

Parameters:
Return type:

None

property learner_eval_sample_weight_param: str | None

Get the name of the sample weight parameter for evaluation sets.

Returns:

The name of the sample weight parameter if supported, else None.

predict(X: ndarray[tuple[Any, ...], dtype[floating]] | DataFrame) ndarray[tuple[Any, ...], dtype[floating]][source]

Predict quantiles for the input features.

Parameters:
Returns:

A 2D array where each column corresponds to predicted quantiles.

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

property models: list[BaseEstimator]

Get the list of underlying quantile models.

Returns:

List of BaseEstimator instances for each quantile.

property has_feature_names: bool

Check if the base estimators have feature names.

Returns:

True if the base estimators have feature names, False otherwise.

set_fit_request(*, eval_sample_weight='$UNCHANGED$', eval_set='$UNCHANGED$', feature_name='$UNCHANGED$', sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters#

eval_sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for eval_sample_weight parameter in fit.

eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for eval_set parameter in fit.

feature_namestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for feature_name parameter in fit.

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns#

selfobject

The updated object.

set_score_request(*, sample_weight='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters#

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns#

selfobject

The updated object.