DisTreebution.QRT package#
Submodules#
DisTreebution.QRT.MinMaxHeap module#
- class DisTreebution.QRT.MinMaxHeap.MinMaxHeap(reserve=0)[source]#
Bases:
objectImplementation of a Min-max heap following Atkinson, Sack, Santoro, and Strothotte (1986): https://doi.org/10.1145/6617.6621
DisTreebution.QRT.RegressionTreeQuantile module#
- class DisTreebution.QRT.RegressionTreeQuantile.RegressionTreeQuantile(quantiles, max_depth=None, min_samples_split=2, IG_biais_correction=None)[source]#
Bases:
objectRegression tree that predicts multiple quantiles.
This tree recursively partitions the feature space to minimize a multiquantile entropy measure. It produces predictions for a list of requested quantiles at each leaf.
- Parameters:
- quantiles list or numpy.ndarray
Sequence of quantile levels to predict (values in (0,1)).
- max_depth int or None
Maximum recursion depth for the tree. If
None, splitting continues until the sample-size criterion is met.- min_samples_split int
Minimum number of samples required in a node to consider a split.
- IG_biais_correction str or None
Whether to use leave-one-out or Mallows adjustments in entropy computations.
- fit(X, y, depth=0, ref_tree=None, max_depth_ref_tree=-1)[source]#
Fit the regression-quantile tree to data.
This method recursively grows the tree. If a split is found it sets
self.feature_indexandself.thresholdand createsleftandrightchild nodes. Otherwise the node becomes a leaf and stores the observedyvalues inself.y.- Parameters:
- X numpy.ndarray
Feature matrix of shape (n_samples, n_features).
- y numpy.ndarray
Target vector of shape (n_samples,).
- depth int
Current depth in recursion (used internally).
- ref_tree RegressionTreeQuantile or None
Optional reference tree whose splits will be reused up to
max_depth_ref_tree.- max_depth_ref_tree int
Maximum depth on
ref_treeto reuse splits from.
- Returns:
None. Tree structure is constructed in-place.
- Return type:
None
- find_best_split(X, y)[source]#
Find the best split for the current node.
The method evaluates candidate splits on every feature and returns the best (feature_index, threshold) pair that satisfies the minimum samples per side criterion and improves the multiquantile entropy (when
self.IG_biais_correctionis “LOO” (resp. “Mallows”) the entropy uses leave-one-out (or Mallows correction) adjustments).- Parameters:
- X numpy.ndarray
Feature matrix for current node.
- y numpy.ndarray
Target values for current node.
- Returns:
Tuple
(feature_index, threshold)for the best split, orNoneif no valid split found.- Return type:
- predict(X)[source]#
Predict quantiles for input samples.
If the node is a leaf the stored quantile values (
self.value) are repeated for each input sample. Otherwise the method routes samples down to child nodes and assembles per-sample quantile predictions.- Parameters:
- X numpy.ndarray
Feature matrix of shape (n_samples, n_features).
- Returns:
Array of shape (n_samples, n_quantiles) with predicted quantile values.
- Return type:
- get_values_leaf(X, indexes)[source]#
Return leaf values and associated sample indexes.
Traverses the tree and collects, for each leaf, a pair containing the list of sample indexes that fall in the leaf and the observed target values stored at that leaf.
- Parameters:
- X numpy.ndarray
Feature matrix of shape (n_samples, n_features).
- indexes numpy.ndarray or list
Array of original sample indices corresponding to rows in
X.
- Returns:
List of items
[indexes_list, y_values]for each leaf encountered.- Return type:
- get_values_leaf_and_groups(X, indexes, current_group_depth='', max_depth_group=1)[source]#
Return leaf values together with group identifiers.
Similar to
get_values_leaf()but also returns a group identifier (a string encoding the path down the tree) for each leaf. Groups are truncated atmax_depth_group.- Parameters:
- X numpy.ndarray
Feature matrix of shape (n_samples, n_features).
- indexes numpy.ndarray or list
Array of original sample indices corresponding to rows in
X.- current_group_depth str
Current group identifier string (used during recursion).
- max_depth_group int
Maximum length of the group identifier to produce.
- Returns:
List of items
[indexes_list, y_values, group_id]for each leaf.- Return type: