DirectRS

class modeva.models.directrs.api.MoDirectRSRegressor(base_model, name=None, construction='C', ridge_alpha=100.0, n_passes=1, n_trees_used=None)[source]

DirectRS post-processor for tree ensemble regressors.

Takes a pre-trained tree ensemble (XGBoost, LightGBM, or CatBoost) and builds a piecewise-linear model that can match or improve the original with per-tree Ridge regression on geometric embeddings φ_t(x) = [1, S’x].

Parameters:
base_modelfitted tree ensemble

Pre-trained XGBoost, LightGBM, or CatBoost regressor (or MoDeVa wrapper).

namestr, optional

Model identifier. Default: “DirectRS”.

constructionstr, default=”C”

Operator construction for geometry extraction: “A” (gain-weighted), “B” (co-occurrence), “C” (value-weighted), “M” (count).

ridge_alphafloat, default=100.0

Ridge regularization for per-tree linear heads.

n_passesint, default=1

Number of backfitting coordinate descent passes.

n_trees_usedint, optional

Number of trees to use. Default: all trees.

fit(X, y, sample_weight=None, X_val=None, y_val=None, verbose=False)[source]

Fit DirectRS on training data.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)
ynp.ndarray of shape (n_samples,)
sample_weightignored (kept for API compatibility)
X_valnp.ndarray, optional
y_valnp.ndarray, optional
verbosebool, default=False
Returns:
self
set_fit_request(*, X_val: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$', verbose: bool | None | str = '$UNCHANGED$', y_val: bool | None | str = '$UNCHANGED$') MoDirectRSRegressor

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
X_valstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for X_val parameter in fit.

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

Metadata routing for sample_weight parameter in fit.

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

Metadata routing for verbose parameter in fit.

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

Metadata routing for y_val parameter in fit.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoDirectRSRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

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.

class modeva.models.directrs.api.MoDirectRSClassifier(base_model, name=None, construction='C', ridge_alpha=100.0, n_passes=1, n_trees_used=None)[source]

DirectRS post-processor for tree ensemble classifiers.

Takes a pre-trained tree ensemble classifier and builds a piecewise-linear model using logistic ridge via IRLS (weighted Ridge on working responses in logit space). Predictions use sigmoid for probabilities.

Parameters:
base_modelfitted tree ensemble

Pre-trained XGBoost, LightGBM, or CatBoost classifier (or MoDeVa wrapper).

namestr, optional

Model identifier. Default: “DirectRS-Cls”.

constructionstr, default=”C”

Operator construction for geometry extraction.

ridge_alphafloat, default=100.0

Ridge regularization for per-tree linear heads.

n_passesint, default=1

Number of backfitting coordinate descent passes.

n_trees_usedint, optional

Number of trees to use. Default: all trees.

fit(X, y, sample_weight=None, X_val=None, y_val=None, verbose=False)[source]

Fit DirectRS on training data for classification.

Parameters:
Xnp.ndarray of shape (n_samples, n_features)
ynp.ndarray of shape (n_samples,)
sample_weightignored
X_valnp.ndarray, optional
y_valnp.ndarray, optional
verbosebool, default=False
Returns:
self
set_decision_function_request(*, calibration: bool | None | str = '$UNCHANGED$') MoDirectRSClassifier

Request metadata passed to the decision_function method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function 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 decision_function.

  • 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in decision_function.

Returns:
selfobject

The updated object.

set_fit_request(*, X_val: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$', verbose: bool | None | str = '$UNCHANGED$', y_val: bool | None | str = '$UNCHANGED$') MoDirectRSClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
X_valstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for X_val parameter in fit.

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

Metadata routing for sample_weight parameter in fit.

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

Metadata routing for verbose parameter in fit.

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

Metadata routing for y_val parameter in fit.

Returns:
selfobject

The updated object.

set_predict_proba_request(*, calibration: bool | None | str = '$UNCHANGED$') MoDirectRSClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba 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 predict_proba.

  • 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, calibration: bool | None | str = '$UNCHANGED$') MoDirectRSClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict 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 predict.

  • 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
calibrationstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for calibration parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MoDirectRSClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

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.