DisTreebution.QRT package#

Submodules#

DisTreebution.QRT.MinMaxHeap module#

class DisTreebution.QRT.MinMaxHeap.MinMaxHeap(reserve=0)[source]#

Bases: object

Implementation of a Min-max heap following Atkinson, Sack, Santoro, and Strothotte (1986): https://doi.org/10.1145/6617.6621

insert(key)[source]#

Insert key into heap. Complexity: O(log(n))

peekmin()[source]#

Get minimum element. Complexity: O(1)

peekmax()[source]#

Get maximum element. Complexity: O(1)

popmin()[source]#

Remove and return minimum element. Complexity: O(log(n))

popmax()[source]#

Remove and return maximum element. Complexity: O(log(n))

DisTreebution.QRT.MinMaxHeap.level(i)[source]#
DisTreebution.QRT.MinMaxHeap.trickledown(array, i, size)[source]#
DisTreebution.QRT.MinMaxHeap.trickledownmin(array, i, size)[source]#
DisTreebution.QRT.MinMaxHeap.trickledownmax(array, i, size)[source]#
DisTreebution.QRT.MinMaxHeap.bubbleup(array, i)[source]#
DisTreebution.QRT.MinMaxHeap.bubbleupmin(array, i)[source]#
DisTreebution.QRT.MinMaxHeap.bubbleupmax(array, i)[source]#
DisTreebution.QRT.MinMaxHeap.peekmin(array, size)[source]#
DisTreebution.QRT.MinMaxHeap.peekmax(array, size)[source]#
DisTreebution.QRT.MinMaxHeap.removemin(array, size)[source]#
DisTreebution.QRT.MinMaxHeap.removemax(array, size)[source]#
DisTreebution.QRT.MinMaxHeap.insert(array, k, size)[source]#
DisTreebution.QRT.MinMaxHeap.minmaxheapproperty(array, size)[source]#
DisTreebution.QRT.MinMaxHeap.test(n)[source]#
DisTreebution.QRT.MinMaxHeap.test_heap(n)[source]#

DisTreebution.QRT.RegressionTreeQuantile module#

class DisTreebution.QRT.RegressionTreeQuantile.RegressionTreeQuantile(quantiles, max_depth=None, min_samples_split=2, IG_biais_correction=None)[source]#

Bases: object

Regression 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_index and self.threshold and creates left and right child nodes. Otherwise the node becomes a leaf and stores the observed y values in self.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_tree to 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_correction is “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, or None if no valid split found.

Return type:

tuple(int, float) or None

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:

numpy.ndarray

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:

list

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 at max_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:

list

DisTreebution.QRT.entropies_MultiQuantiles module#

DisTreebution.QRT.entropies_MultiQuantiles.level2idx(n, q)[source]#
DisTreebution.QRT.entropies_MultiQuantiles.get_entropy(values, quantiles)[source]#
DisTreebution.QRT.entropies_MultiQuantiles.get_entropy_multiquantiles(heap2sum, heaps, quantiles, n)[source]#
DisTreebution.QRT.entropies_MultiQuantiles.get_max_heaps_minus(i_qp, heaps)[source]#
DisTreebution.QRT.entropies_MultiQuantiles.get_min_heaps_plus(i_qp, heaps)[source]#
DisTreebution.QRT.entropies_MultiQuantiles.OLD_LOO_quantiles(y, entropy, quantiles)[source]#
DisTreebution.QRT.entropies_MultiQuantiles.LOO_quantiles(y, entropy, quantiles, heaps)[source]#
DisTreebution.QRT.entropies_MultiQuantiles.entropies_MultiQuantiles(order, y, quantiles, IG_biais_correction=None)[source]#

Module contents#