XGBoostSplitter#

class XGBoostSplitter(lam, approximation=None, n_quantiles=32, min_cover=1, n_jobs=1)[source]#

Bases: RuleTreeBaseSplitter

Splitter for regression that maximizes the XGBoost gain: the similarity scores of the two children minus the one of the node, where the target are the residuals of the previous trees.

Parameters:
  • lam (float) – L2 regularization of the leaf values: the similarity score of a node is sum(residuals) ** 2 / (n + lam).

  • approximation ({None, 'quantile'}, default=None) – With ‘quantile’, only n_quantiles thresholds (quantiles) are tested on each numerical feature, instead of all the values.

  • n_quantiles (int, default=32) – Number of thresholds tested with approximation=’quantile’.

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

  • n_jobs (int, default=1) – Not used.

Variables:
  • feature (int) – Column of the feature matrix used by the split.

  • threshold (float) – Threshold of the split.

  • is_categorical (bool) – Whether the split is categorical.

  • gain (float) – XGBoost gain of the split.

  • impurity (list of float or None) – Not computed (None).

  • similarity_r (root_similarity, similarity_l,) – Similarity scores of the node and of the two children.

See also

XGBoostStumpRegressor

the stump made of a MatrixTransformer and this splitter.

Examples

>>> from sklearn.datasets import load_diabetes
>>> from RuleTree.stumps.splitters import XGBoostSplitter
>>> X, y = load_diabetes(return_X_y=True)
>>> splitter = XGBoostSplitter(lam=1)
>>> splitter = splitter.fit(X, y - y.mean(), numerical=list(range(10)), categorical=[],
...                         context=None, node_id=None, cache=None)
>>> splitter.feature_
8
task = 'reg'#
get_threshold_values(X, feature_idx, categorical)[source]#

Values tested for a feature: its values (categorical), the midpoints between its consecutive values (numerical) or, with approximation=’quantile’, n_quantiles quantiles.

Parameters:
  • X (numpy.ndarray of shape (n_samples, n_features)) – Feature matrix.

  • feature_idx (int) – Column of the feature.

  • categorical (list of int) – Indices of the categorical columns.

Returns:

thresholds

Return type:

numpy.ndarray

fit(X, y, numerical, categorical, sample_weight=None, check_input=True, *, context, node_id, cache)[source]#

Find the split with the highest XGBoost gain among all the features and thresholds.

Parameters:
  • X (numpy.ndarray of shape (n_samples, n_features)) – Feature matrix of the instances in the node.

  • y (numpy.ndarray of shape (n_samples,)) – Target of the instances in the node.

  • numerical (list of int) – Indices of the numerical columns of X.

  • categorical (list of int) – Indices of the categorical columns of X.

  • sample_weight (numpy.ndarray of shape (n_samples,), default=None) – Sample weights of the instances in the node.

  • check_input (bool, default=True) – Whether to check the input data.

  • context (RuleTree or None) – Tree being built, None outside a tree.

  • node_id (str or None) – Identifier of the node, e.g. "Rl" (context.get_node_by_id(node_id)), None outside a tree.

  • cache (dict or None) – Cache of the tree (namespace -> dictionary of values), None outside a tree: the component decides whether and how to use it (the ones of the library use self._get_cache(cache)).

Returns:

self – The fitted splitter.

Return type:

XGBoostSplitter

Raises:
update_statistics(X, y, sample_weight=None, *, context, node_id, cache)[source]#

Recompute the similarity scores and the gain of the split (gain and gain_).

Parameters:
  • X (numpy.ndarray of shape (n_samples, n_features)) – Feature matrix of the instances in the node.

  • y (numpy.ndarray of shape (n_samples,)) – Target of the instances in the node.

  • sample_weight (numpy.ndarray of shape (n_samples,), default=None) – Sample weights of the instances in the node.

  • context (RuleTree, default=None) – The tree, None outside a tree.

  • node_id (str, default=None) – Identifier of the node, e.g. "Rl" (context.get_node_by_id(node_id)), None outside a tree.

  • cache (dict, default=None) – Cache of the tree, when called by it; None otherwise.