RuleTreeXGBoostRegressor#

class RuleTreeXGBoostRegressor(gamma=0, lam=1, max_depth=6, min_cover=1, n_jobs=1, base_stumps=None, max_leaf_nodes=inf, min_samples_split=2, prune_useless_leaves=True, stump_selection='random', random_state=None)[source]#

Bases: RuleTreeRegressor

RuleTreeRegressor with the splits and the leaf values of XGBoost, used as base estimator of XGBoostRegressor (fitted on the residuals).

The splits maximize the XGBoost gain (see XGBoostStumpRegressor); after fit, the splits with a gain lower than gamma are pruned and each leaf predicts sum(y) / (n + lam).

Parameters:
  • gamma (float, default=0) – Minimum gain of a split.

  • lam (float, default=1) – L2 regularization of the leaf values and of the similarity scores.

  • max_depth (int, default=6) – Maximum depth of the tree.

  • min_cover (float, default=1) – Minimum cover (number of instances) of each child.

  • n_jobs (int, default=1) – Passed to the stumps.

  • base_stumps (XGBoostStumpRegressor, default=None) – If None or not an XGBoostStumpRegressor, XGBoostStumpRegressor(lam, min_cover, n_jobs) with a warning.

  • max_leaf_nodes – As in RuleTreeRegressor.

  • min_samples_split – As in RuleTreeRegressor.

  • prune_useless_leaves – As in RuleTreeRegressor.

  • stump_selection – As in RuleTreeRegressor.

  • random_state – As in RuleTreeRegressor.

Variables:

root (RuleTreeNode) – Root of the fitted tree; the prediction of each leaf is its XGBoost value.

See also

RuleTree.ensemble.XGBoostRegressor.XGBoostRegressor

the boosting of these trees.

Examples

>>> from sklearn.datasets import load_diabetes
>>> from RuleTree.stumps.regression import XGBoostStumpRegressor
>>> from RuleTree.tree.RuleTreeXGBoostRegressor import RuleTreeXGBoostRegressor
>>> X, y = load_diabetes(return_X_y=True)
>>> tree = RuleTreeXGBoostRegressor(max_depth=2, lam=1, base_stumps=XGBoostStumpRegressor(lam=1))
>>> tree = tree.fit(X, y - y.mean())  # residuals of the mean
>>> tree.get_rules()["textual_rule"]
'X_8 <= -0.004'
fit(X: array = None, y: array = None, X_ts=None, X_img=None, X_txt=None, sample_weight=None)[source]#

Fit the tree, prune the splits with a gain lower than gamma and set the leaf values.

Parameters:
  • X (numpy.ndarray of shape (n_samples, n_features), default=None) – Tabular data.

  • y (numpy.ndarray of shape (n_samples,), default=None) – Target (residuals, in XGBoostRegressor).

  • X_ts (default=None) – Other data types, see RuleTree.fit.

  • X_img (default=None) – Other data types, see RuleTree.fit.

  • X_txt (default=None) – Other data types, see RuleTree.fit.

  • sample_weight (numpy.ndarray of shape (n_samples,), default=None) – Sample weights, passed to the stumps.

Returns:

self

Return type:

RuleTreeXGBoostRegressor

Raises:

EmptyXGBTreeException – If the pruning removes all the splits.