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,RegressorMixinAdaptor 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:
X (
ndarray[tuple[Any,...],dtype[floating]] |DataFrame) – Input features as a DataFrame.y (
ndarray[tuple[Any,...],dtype[floating]] |Series) – Target values as a 2D array where each column corresponds to a quantile.sample_weight (
ndarray[tuple[Any,...],dtype[floating]] |Series|None) – Sample weights for training data.eval_set (
list[tuple[DataFrame,ndarray[tuple[Any,...],dtype[floating]]]] |None) – Evaluation set for early stopping.eval_sample_weight (
list[ndarray[tuple[Any,...],dtype[floating]]] |list[Series] |None) – Sample weights for evaluation data.X
y
sample_weight
feature_name
eval_set
eval_sample_weight
- Return type:
- 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.
- 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
fitmethod.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(seesklearn.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 tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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_weightparameter infit.- eval_setstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
eval_setparameter infit.- feature_namestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
feature_nameparameter infit.- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter infit.
Returns#
- selfobject
The updated object.
- set_score_request(*, sample_weight='$UNCHANGED$')
Configure whether metadata should be requested to be passed to the
scoremethod.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(seesklearn.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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_weightparameter inscore.
Returns#
- selfobject
The updated object.