Methods · e2tree

From black box to
transparent rules.

e2tree turns the ensemble's internal structure into a pairwise dissimilarity matrix, then uses that matrix to grow a single decision tree. This page covers the math behind each step.

O
Co-occurrence matrix
D = 1 − O
D
Dissimilarity matrix
drives the split criterion
𝓣
e2tree structure
single interpretable tree
LOI
Local Importance
observation-level explanations
Dissimilarity

Encoding the ensemble in a single matrix.

A tree-based ensemble of B trees assigns every observation to a terminal node in each tree. Two observations that frequently share a terminal node are, in the ensemble's view, similar. This intuition is formalised as the co-occurrence matrix O.

Each entry is a weighted co-occurrence measure. The numerator accumulates the node goodness-of-fit Wtij|b each time observations i and j share a leaf; the denominator normalises by the larger of the two marginal sums:

The corresponding dissimilarity matrix is:

For classification, Wtij|b = Rt is the correct classification rate of the node where i and j meet in tree b (proportion of correctly classified training observations in that node). D is symmetric, non-negative, with zero diagonal, and values in [0, 1]. Computed by createDisMatrix(), with optional parallelisation.

e2tree proximity heatmap showing ensemble co-occurrence structure
Figure 1 Proximity heatmap produced by eValidation(). Warmer cells indicate higher co-occurrence frequency (lower dissimilarity); the block structure reflects the underlying class separation learned by the ensemble.
e2tree classification tree on iris dataset
Figure 2 e2tree applied to the iris dataset. The single tree recovers the three species using just two variables (Petal.Length and Petal.Width), mirroring the splits favoured by the underlying ensemble.
Tree construction

Growing the explainable tree.

e2tree() constructs the tree recursively. At each node the algorithm searches for the binary split — over all predictors and candidate thresholds — that maximises the reduction in within-group weighted dissimilarity:

Impurity at a node is the average intra-group dissimilarity. Splitting continues until any stopping rule is triggered:

  • · impTotal — minimum node impurity to attempt a split
  • · maxDec — minimum impurity decrease required
  • · n — minimum observations in a node
  • · level — maximum tree depth
Classification

Any labelled dataset — any ensemble.

In the classification setting, the response variable is a factor. e2tree computes the dissimilarity matrix from the ensemble's proximity (co-occurrence in terminal nodes), then fits a tree whose leaf predictions are the majority class within each node.

Terminal node purity — the proportion of observations belonging to the predicted class — provides a local measure of classification confidence. The tree produces decision rules domain experts can read directly.

Leaf node prediction for a new observation follows the standard CART convention: route the observation through the split rules to a terminal node; the prediction is the majority class of the training observations in that node, weighted by the ensemble's dissimilarity structure.

iris

Classic multiclass benchmark

Three-class problem on 150 observations. e2tree recovers perfect setosa separation and near-perfect discrimination between versicolor and virginica in 6 terminal nodes — with 2 split variables.

3 classes4 predictors6 leaves
credit

Binary credit scoring

Included in the package as data(credit). Demonstrates e2tree on an imbalanced binary classification task typical in real-world finance and risk modelling.

binaryimbalanced
e2tree on iris — variable importance
Figure 3 Variable importance from the e2tree classification model on iris. Petal variables dominate, consistent with the underlying ensemble.
e2tree classification tree visualization
Figure 4 rpart.plot rendering of the e2tree. Decision rules are human-readable and readily communicable to non-technical stakeholders.
Regression

Continuous targets, same transparent logic.

Extending e2tree to regression required redefining the goodness-of-fit weight W. The co-occurrence formula has the same structure as the classification case, but the weight now uses the normalised mean squared error (NMSE) at the node: nodes where the ensemble predicts poorly contribute less to the co-occurrence of their observations.

Formally, the regression weight is defined as:

where , p(t) = n(t)/N is the proportion of observations in node t, and MSEmax is the theoretical maximum MSE under the Jacobson bound. Two observations sharing a leaf only count toward co-occurrence to the extent that the ensemble predicts accurately in that node.

The extension is fully described in the 2026 paper in Applied Stochastic Models in Business and Industry. The R implementation follows the same workflow as the classification case.

# Regression example — mtcars ensemble_reg <- randomForest( mpg ~ ., data = training, ntree = 500, importance = TRUE, proximity = TRUE ) D_reg <- createDisMatrix( ensemble_reg, data = training, label = "mpg", parallel = list(active = FALSE) ) setting <- list(impTotal = 0.1, maxDec = 0.01, n = 2, level = 4) tree_reg <- e2tree( mpg ~ ., training, D_reg, ensemble_reg, setting )
e2tree regression tree on mtcars
Figure 5 e2tree regression tree on the mtcars dataset. The tree partitions the feature space into regions of similar predicted fuel economy (mpg), with leaf values representing group means.
Predicted vs actual — e2tree regression
Figure 6 Predicted vs. observed values for the regression e2tree on the test set. The piecewise structure is clearly visible; overall fit remains competitive with the full ensemble.
Validation

eValidation — structural fidelity.

eValidation() measures how closely the e2tree's proximity structure matches the original ensemble's. It computes concordance between O and the tree's own proximity matrix, returning a numeric score and a heatmap.

  • · measures() — quantitative concordance metrics
  • · proximity() — tree proximity heatmap
  • · plot() — visualise fidelity
eValidation proximity comparison
Figure 7 Side-by-side comparison of ensemble-induced proximity (left) and e2tree-induced proximity (right), confirming high structural fidelity.
Local importance

loi — per-observation explanations.

While vimp() summarises the overall contribution of each predictor, Local Observation Importance (loi()) attributes importance at the individual observation level — so you can explain why the model reached a specific conclusion for a specific case.

The local importance score for observation and variable is defined as:

where measures the change in the node's dissimilarity when variable j is excluded from the split at the node to which i belongs.

  • · loi() — local importance scores per observation
  • · loi_perm() — permutation-based significance
  • · plot() — visualise importance landscape
Local Observation Importance plot
Figure 8 Local Observation Importance for the iris classification model. Each bar is one observation; colour encodes predicted class, height encodes local importance.

Ready to explain your ensemble?

Install from CRAN and run the five-step workflow in a few minutes.