Skip to content

e2tree

1.2.0Package record

Explainable Ensemble Trees

0packages dependsuggested by 1
4.3Kdownloads / year
23.0%test coverage
13/13flavors OK

Overview

About

The Explainable Ensemble Trees 'e2tree' approach has been proposed by Aria et al. (2024) doi:10.1007/s00180-022-01312-6. It aims to explain and interpret decision tree ensemble models using a single tree-like structure. 'e2tree' is a new way of explaining an ensemble tree trained through 'randomForest' or 'xgboost' packages.

Changes in 1.2.0

Robustness fixes (2026-05)

  • **CatBoost multi-class leaf extraction**: for multi-class objectives (MultiClass, MultiClassOneVsAll) catboost.predict(..., prediction_type = "RawFormulaVal", ntree_start, ntree_end) returns an n_obs x n_classes matrix rather than a scalar vector, which broke the leaf-proxy assignment with Error in leaf_mat[, t] <- as.integer(factor(round(raw, digits = 10L))) : number of items to replace is not a multiple of replacement length. The CatBoost adapter now collapses the per-tree raw-score matrix into a single key per observation (concatenation of the rounded class scores) before discretising into a leaf proxy. The single-output regression case is unchanged.
Show all changes in 1.2.0Hide the rest of the changes in 1.2.0
  • **CatBoost loss-function parsing**: in some catboost releases the loss_function returned by catboost.get_model_params() is a list (e.g. list(type = "MultiClass", border = 0.5)) instead of a bare character scalar. The previous detection code piped this list directly into startsWith() and failed with Error: non-character object(s). The new .catboost_extract_loss() canonicalises any of the documented shapes (plain character, list-with-type, list-with-name, list whose first element holds the name) to a length-one character string before classification/regression dispatch and falls back to attr(ensemble, "params") when catboost.get_model_params() does not expose the loss.
  • **CatBoost 1.2.x compatibility**: starting from catboost 1.2 the R objects returned by catboost.train() carry the class catboost.Model instead of the previous catboost.CatBoost. All three S3 generics in the adapter layer (get_ensemble_type, extract_terminal_nodes, get_ensemble_predictions) now register methods for both class names, sharing a single internal worker, so models trained with either version are accepted out of the box. ensemble_backend() and .SUPPORTED_BACKENDS recognise both class names. createDisMatrix() now sets the e2tree_label attribute on CatBoost ensembles automatically when the user passes label, eliminating the previously required manual attr(ensemble, "e2tree_label") <- ... step.
  • **moda() accepts non-factor responses**: classification ensembles trained on integer 0/1 responses (typical of gbm with the bernoulli distribution) no longer trigger Error in res[1] <- as.character(levels(x)[res[1]]) : replacement has length zero. The internal moda() helper now coerces the modal value to character independently of whether the response is a factor, an integer, a character or a numeric vector. Affected call sites: eStoppingRules(), e2tree(), vimp().
  • **Vignette models.Rmd corrected**: the regression examples now pass the response column through data together with label = "<response_name>", as required by createDisMatrix() for regression backends; the gbm regression example sets n.minobsinnode = 2 and bag.fraction = 0.8 so it does not fail the gbm internal sample-size check on the small mtcars training set; the lightgbm regression example uses num_leaves = 8 and min_data_in_leaf = 2, which prevents the small-sample degenerate case caught by validate_terminal_nodes(). The classification example based on the binary is_setosa indicator now passes a factor copy of the response to e2tree() while leaving the numeric copy to gbm.

Multi-backend hardening (2026-04)

  • **Adapter contract validation**: createDisMatrix() now calls validate_terminal_nodes() immediately after extract_terminal_nodes(). Malformed adapter output (wrong row count, non-numeric leaf columns, or the all-same-leaf degenerate case that previously made GBM silently produce an all-zero D) is now rejected with an informative error.
  • **Backend tagging**: dissimilarity matrices returned by createDisMatrix() carry a new ensemble_backend attribute identifying the backend used. e2tree() and as.rpart() warn when the supplied ensemble does not match this tag, catching the common "stale D reused with a different model" mistake.
  • **xgboost 3.x compatibility**: models built via the high-level xgboost::xgboost() wrapper (which adds an xgboost class on top of xgb.Booster) are now handled correctly; previously the wrapper's predict.xgboost method rejected xgb.DMatrix input and broke leaf extraction.
  • **Chunked dissimilarity path wired in**: when chunk_size < n_obs the function now actually uses compute_dissimilarity_chunked() (previously the parameter was accepted but ignored). Optional use_disk = TRUE persists the result via saveRDS().
  • **C++ type checks**: compute_cooccurrences_cpp(), compute_cooccurrences_sparse_cpp() and compute_all_cooccurrences_cpp() now validate that Tree* and resp columns are integer/double, raising a clear error rather than silently coercing factors/characters to zeros.
  • **Adapter de-duplication**: the three S3 generics share a single .unsupported_backend() helper and a single supported-classes list; the xgboost adapters share a .xgb_dmatrix() builder.
  • **Documentation**: ?createDisMatrix now contains an "Interpretation note (RF vs boosting)" section explaining why the dissimilarity scale differs systematically between bagging and boosting backends.
  • **Tests**: new tests/testthat/test-multi-backend.R exercises the D invariants (square, zero diagonal, symmetric, non-degenerate, correctly tagged) for each available backend, and covers the validator and the default-method failure paths.

S3 class system overhaul

  • e2tree class now properly listed as first in the class vector (c("e2tree", "list")).
  • New S3 methods for e2tree: predict(), fitted(), residuals().
  • predict.e2tree() replaces ePredTree() as the standard prediction interface. For regression, returns a data frame with fit and sd (node-level standard deviation). For classification, returns a data frame with fit, accuracy, and score.
  • fitted.e2tree() returns fitted values for training data.
  • residuals.e2tree() returns residuals for regression E2Trees.
  • methods(class = "e2tree") now shows: as.rpart, e2splits, fitted, nodes, plot, predict, print, residuals, summary.
  • methods(class = "eValidation") now shows: measures, plot, print, proximity, summary.

Accessor functions (new)

  • nodes(): Extract tree node data frame from an e2tree object, with optional terminal filter.
  • e2splits(): Extract split and categorical split information.
  • measures(): Extract validation measures from an eValidation object.
  • proximity(): Extract proximity matrices (ensemble, e2tree, or both) from an eValidation object.

Coercion methods (new)

  • as.rpart(): Generic and method for converting e2tree to rpart format.
  • as.party(): Method for converting e2tree to partykit's constparty format (registered conditionally when partykit is installed). Produces proper bar plots in terminal nodes for classification trees.
  • rpart2Tree() retained for backward compatibility with a deprecation note.

Validation framework improvements

  • eValidation() gains a test argument: "mantel" (Mantel test only), "measures" (divergence/similarity measures only), or "both" (default). This allows choosing between association testing and agreement testing.
  • print.eValidation(), summary.eValidation(), and plot.eValidation() updated to handle all three test modes gracefully.

Variable importance improvements

  • vimp(): Auto-detects classification/regression from the e2tree object; type argument now optional.
  • Fixed incorrect y-axis label ("Variance" instead of "Variable") in variable importance plots.
  • Regression variable importance bars now sorted by importance (previously unsorted).
  • Consistent column naming (Variable, MeanImpurityDecrease) across classification and regression.
  • Internal logic refactored into .vimp_classification() and .vimp_regression().

Documentation

  • All man page titles standardized to Title Case.
  • \dontrun{} replaced with \donttest{} in all examples; interactive-only examples wrapped in if (interactive()).
  • Examples updated to use accessor functions and predict() instead of direct $ access.
  • New vignette e2tree-introduction covering classification, regression, validation (Mantel test, divergence measures, LoI decomposition), and comparison with partykit/stablelearner.
  • ePredTree() documentation updated with deprecation note pointing to predict.e2tree().

Package infrastructure

  • Added partykit, knitr, rmarkdown to Suggests.
  • Added VignetteBuilder: knitr to DESCRIPTION.
  • e2tree object now stores fitted.values, y, and data for S3 method support.
  • Conditional .onLoad hook for registering as.party.e2tree when partykit is loaded.

From NEWS.md in the release

Install

Health

CRAN checks
13OK
Slowest check: 5.0 min · r-devel-windows-x86_64
Status changes
  • OK13 OK2026-08-05
  • NOTE12 OK, 1 NOTE2026-08-01
  • OK14 OK2026-04-22
  • ERROR13 OK, 1 ERROR2026-04-18
  • OK14 OK2026-03-10
Advisories

none known

Documentation

In release 1.2.0
READMEYes · 953 wordsVignettesYes · 2 · dynamicNEWSYes · 100% structured · mentions 1.2.0Citation fileYes · cites a publication
Help pages
34 (5 internal)
Examples that run
0%17 only when donttest examples are enabled (R CMD check --as-cran)
Exported functions with examples
59%
Documented parameters
96%
Return-value docs
91%
Help pages citing references
0%

Downloads

4.3K
CRAN downloads in the past year
Rank #8,028 · ~12/day · ~354/mo
Daily download trend is not available in this view yet.
43730 days
1.1K90 days
4.3K1 year
Compare downloads with other packages →
Also on392 r2u4 autocran

Repository

8Stars
3Forks
0Open issues
0Open PRs
3Releases
158Commits
6Commit identities
explainable-machine-learning
158 commits · Last activity 2026-05-16 · 0% stars, 30d · Default branch at 1.2.0.9000, ahead of CRAN 1.2.0 (checked 2026-10-18)
Responsiveness
How these are sampled
PRs merged (all time)
91%
Median days to close, 50 most recently updated closed issues
21
Median days to close, 50 most recently updated closed PRs
0

Stars over time

2025-10-10 · 72026-07-07 · 8
PracticesBeta

4 development-tooling and community-health practices detected across 2 families in the upstream repository

Checks run against github.com/massimoaria/e2tree on 2026-10-18.

Continuous integration (2)
GitHub ActionsR CMD check workflow

The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel

Docs source (2)
README.Rmd

GitHub Pages site last deployed 2023-05-29

How this is detected·Detection ruleset v3 (2026-09-26)

Dependencies

Declared dependencies
25 external dependencies (excludes base and recommended)

Installing e2tree adds 44 packages (23 with compiled code, 36 MB of source tarballs). Heaviest: stringi 11 MB, ggplot2 6.0 MB, Rcpp 1.8 MB.

Depends (1)
R >= 3.5
LinkingTo (1)
Enhances (0)
none
Reverse dependencies
0direct
0indirect
Suggested by 1
Suggests, most downloaded first

Datasets

People & History

People (2)
Author, Maintainer since 0.1.2 (2025), Copyright holder
Author, Copyright holder
Releases (4)

Pick two releases to compare their code metrics.

  • 1.2.0Latest
    record
    2026-05-15 · current release · diff ↗ ·
    removed 3 exports
    goi, goi_analysis, goi_perm
    added 10 exports
    as.rpart, e2splits, extract_terminal_nodes, get_ensemble_predictions, get_ensemble_type, loi, loi_perm, measures, nodes, proximity
  • R
    R 4.6.0 released · 2026-04-24
  • 1.0.0
    record
    2025-07-16 · diff ↗ ·
    removed 1 export
    eComparison
    added 9 exports
    eValidation, goi, goi_analysis, goi_perm, plot_e2tree, plot_e2tree_click, plot_e2tree_vis, print_e2tree_summary, save_e2tree_html
  • 0.2.0
    record
    2025-07-16 · diff ↗
  • 0.1.2
    record
    2025-04-12
  • R
    R 4.5.0 released · 2025-04-11

Package metadata

First published
2025-04-12
Total releases
4 / 1 yrs
License
MIT + file LICENSE OSI
Minimum R
≥ 3.5
Bundled data
2.1 KB / 1 file
Download size
3.4 MB

Cite

Cite this package

Run in R for the authors' entry:

citation("e2tree")

The package provides a citation file, so citation() returns the authors' own entry.

It points to 10.1007/s00180-022-01312-6, 10.1002/asmb.70064.

Cite the R Observatory

For a number measured here: a download total, a coverage figure, an archival date.

APA

Balamuta, J. J. (2026). R Observatory: Metrics for e2tree version 1.2.0 [Data set]. HJJB, LLC. Data release v2026-10-21. https://doi.org/10.5281/zenodo.21843040

From data release v2026-10-21, which the citation names so these numbers can be found later. More on citing and the projects behind them.

Report a problem with this page →

Privacy choices

These apply to this browser and are stored on this device only. Nothing about your choice is sent to us.

Read the privacy policy