Changelog
Source:NEWS.md
glex 0.7.0.9000 (development version)
glex()supportsrangermodels with factor features under everyrespect.unordered.factorsoption. Pass the training-styledata.frameasx: factors are encoded as inpredict(), including the response-based level order of"order","partition"splits are evaluated as level sets, and$xkeeps the factor columns. Previously, factor columns errored and"partition"models failed.weighting_method = "empirical"errors on"partition"splits.glex()methods warn about arguments they do not use instead of silently ignoring them, e.g.glex(rp, x, weighting_method = "fastpd")for anrpfmodel, which has no weighting method, or a misspelledweighting_methdforxgboostandranger.Multiclass terms such as
mpg__class:4no longer count the class suffix as an interaction, soprint()reports the correct maximum degree for multiclassrpfmodels.New
plot_waterfall()andplot_force()show how a single prediction is built from the components of the decomposition, one bar or segment per main or interaction term, from E[f] to f(x). Small terms are aggregated viamax_terms,thresholdandmax_interaction; constrained decompositions end with a remainder bar (#49).plot_waterfall(),plot_force(),plot_shap_decomposition()andplot()forglex_vi()aggregate terms smaller than 2.5% of the largest one by default (threshold = NULL), so negligible components no longer crowd the plot;threshold = 0shows all terms. Value labels are rounded to the precision the plotted range allows, and labels of values that round to zero are omitted while their bars are still drawn.plot()methods replace theautoplot()methods forglexandglex_viobjects, so plotting no longer needs ggplot2 attached:plot(gl, "hp")picksplot_main_effect(),plot_twoway_effects()orplot_threeway_effects()by the number of predictors, andplot(glex_vi(gl))plots importances. Theautoplot()methods are removed. Theplot_*()functions remain the explicit interface.glex_explain()is renamed toplot_shap_decomposition(), which says what it shows: how each feature’s SHAP value is assembled from the components it is part of.glex_explain()still works but is deprecated. The plot no longer clips labels, places values beside the bars and the SHAP value in its own bottom row, drops empty rows in facets, and keeps “Remaining terms” directly above the SHAP value.Multiclass
rpfmodels now carry one intercept per class (fixed upstream in randomPlantedForest), andglex_vi(),plot_shap_decomposition(),plot_waterfall()andplot_force()use each class’s intercept. Constraints on multiclassrpfdecompositions are now confirmed against the model’s predictions like for other models, so a constraint that only drops zero terms keeps the SHAP values, and$remainderis computed by glex for each class.print()and the plot captions now use singular forms where appropriate (“1 observation”, “1 term”).glex()supports the models thatrpf()of randomPlantedForest returns by default from version 0.6 (classrpf_pruned):glex(model, x)returns the model’s components atxas it predicts (each scaled by its coefficient), summing with the intercept to the prediction, with SHAP values andmax_interaction/featuresconstraints as for the other models, soplot_waterfall(),plot_force()andplot_shap_decomposition()work on it as for a forest. It also carries$pruned, the model’s description of its components (coefficients, the cells of those of three or more predictors). Every glex function works on it.glex.rpf()is unchanged; fit withprune = FALSEfor the whole forest.Plots of such models show the model as it predicts:
plot_twoway_effects()draws a pair as a heat map on a grid of the data’s values (resolutioncells per predictor),plot_threeway_effects()(andplot()for any number of predictors) a component of three or more predictors as heat maps, one per cell of its other predictors, each labelled by its cell, andplot_main_effect()main effects as step curves. For multiclass models every plot has one panel (set) per class.plot()of aglexobject withoutpredictorsdraws the whole model in one figure (with patchwork), each component titled by its name and importance atx(measure: share of the variance of the prediction, or mean absolute value in units of the prediction), the most important first: for a model of classrpf_prunedevery component, for other models the main effects and pairs (max_components, default 12). New argumentsmeasure,max_components,ncolandresolution.glex_vi()gainsmeasure:"mean_abs"(the default, unchanged: the mean absolute value, how far a term moves a typical prediction),"variance"(the mean square, what dropping the term costs in squared error, and inm_relits share of the variance of the prediction; summed over classes for multiclass models) and, for models of classrpf_pruned,"share"(the shareprune_components()measured on the training rows, before the coefficients).plot()of aglex_vi()object labels its axis by the measure; its defaultthreshold(2.5% of the largest score) applies to the chosen measure.
glex 0.7.0
Breaking changes
-
$shapis now a scalarNA(with a warning) when the decomposition is constrained viamax_interactionorfeatures: a constrained decomposition does not sum to the full model prediction, so SHAP values cannot be reconstructed from it without violating the efficiency property. Previously, misleading values were returned.$mis unaffected. Supersedes #18, closes #13.
New features
glex()supportsxgboostmodels with categorical features, i.e. models fit on adata.framewith factor columns viaxgboost()orxgb.train()on anxgb.DMatrixbuilt from one. Pass the samedata.frameasx; the factor columns are kept in$x, so plots treat them as categorical. Factor levels must match the training data in order, as forpredict(). Trees are now read from the model’s JSON representation instead ofxgb.model.dt.tree(), which refuses such models.weighting_method = "empirical"does not support categorical splits and errors.New
group_components()aggregates the terms of a decomposition so that a set of features is treated as one feature (#26), e.g. re-assembling a dummy-encoded factor:group_components(gl, groups = list(f = c("fa", "fb", "fc"))). The regrouping is exact (components still sum to the prediction, group SHAP values are sums of member SHAP values), and$xgains a reconstructed factor for dummy-encoded groups so the plot functions work on grouped objects. The companiondummy_groups()derives thegroupslist from the original un-encoded data, matchingmodel.matrix()column naming by default and taking anamingfunction for other encoding schemes. The new vignette “Categorical features” walks through native factors, one-hot groups and semantic groups.glex()objects gain a$constrainedfield naming the arguments that constrained the decomposition (character(0)if complete), solength(x$constrained) > 0tells you whether$shapis usable.A requested constraint only invalidates
$shapif it actually drops something: a model can contain a high-order term whose value is zero, in which case dropping it leaves the decomposition (and the SHAP values) unchanged.glex()confirms the constraint against the model’s own predictions and, if the dropped terms were inert, keeps$shapand emits a message instead of a warning.glex()onrandomPlantedForestmodels now returns$shapas well, computed from the components like for the other model classes (for multiclass models,$shapcolumns are class-specific like those of$m). Previously the field was absent. Constraining the decomposition post-hoc viamax_interactionorfeaturesis now detected forrpfmodels too, where it previously passed silently.glex()objects gain a$remainderfield: what the constraint’s dropped terms are collectively worth, per observation, on the scale of$m. It is present exactly when the decomposition is constrained, sointercept + rowSums(m) + remainderreconstructs the model prediction whether or not a constraint was applied.randomPlantedForestobjects already carried a$remaindercomputed bypredict_components(), but the other model classes did not; the two are now one field with one definition, computed in one place. Closes #11, supersedes #25. Unlike #25, this covers classification and other non-identity links: the remainder is taken on the scale the model is decomposed on, so forxgboostit is on the link scale (plogis(intercept + rowSums(m) + remainder)recovers abinary:logisticprobability), whilerangerprobability forests andrandomPlantedForestare decomposed on the response scale directly.print()on aglexobject reports when the decomposition is constrained.
Bug fixes
Term names of
xgboostandrangerdecompositions no longer depend on the column order ofx: the defaultfastpdandpath-dependentmethods named interaction terms in feature-index order (e.g.wt:hp), while the plotting functions andsubset_components()look up the sorted name (hp:wt), so interaction plots failed for any model whose features are not in alphabetical order. Terms are now always sorted, as forweighting_method = "empirical".glex()now confirms the decomposition of binary models fit withxgboost()(classxgboost) against the margin. Previouslypredict()silently returned probabilities for those, as its method ignoresoutputmargin.Plotting a term that is not part of the decomposition now fails with an informative error instead of
non-numeric argument to mathematical function. Tree models only yield components for feature subsets that occur together in at least one tree, so e.g.plot_twoway_effects()on two features never split on together (common with one-hot encoded categoricals) has nomcolumn to plot.glex()now warns whenxcontains missing values (#41): splits are evaluated without the model’s learned missing-value direction, so the decomposition of rows withNAs is unreliable and does not sum to the model prediction. Proper missing value support needs more investigation; previously such input passed silently.glex()onxgboostmodels fit with early stopping now decomposes only the trees up tobest_iteration, matching whatpredict()evaluates by default. Previously all fitted trees were decomposed, so the components did not sum to the prediction. Closes #42.For
randomPlantedForestclassification models,glex()now confirms the constraint againstpredict(type = "numeric")rather than the defaulttype = "prob". rpf decomposes the raw score, whiletype = "prob"applies rpf’s response function (a clamp to[0, 1]forloss = "L2", the inverse link for"logit"and"exponential") and for binary models returns the classes in an order whose first column is not the one being decomposed. The components reconstruct the raw score exactly, so$remaindernow measures only what the dropped terms are worth, instead of silently absorbing the back-transformation and the class mix-up.
Other
randomPlantedForest (>= 0.3.0)is now required (inSuggests:): it fixes an out-of-bounds read inpurify_3()that crashed R on Windows (PlantedML/randomPlantedForest#61), so rpf tests and examples run on all platforms.glex_explain()now reads SHAP values from$shapinstead of recomputing them from the components, so theglexobject is the single source of truth. The SHAP reference bar is omitted for constrained decompositions, where it previously showed a value reconstructed from the constrained components, and for objects created by earlier versions of glex, which have no$shap.glex now declares
R (>= 4.1.0): the tests use the native pipe and lambda shorthand, which the previousR (>= 3.0)did not reflect.
glex 0.6.0
- Extended compatibility with
xgboost, now requiringxgboost (>= 3.0.0)inSuggests:- Updated tests and examples for the new API
- Plot colors are now configurable via
options()and documented in?glex_options:glex.palette(diverging palette for continuous interaction effects;NULLfor the default shap-style gradient, or the name of a scico palette),glex.palette_discrete(palette for categorical predictors: a color vector,"okabe-ito", a scico palette name, or a brewer palette name),glex.colors_sign(negative/positive colors inglex_explain()and gradient endpoints), andglex.color_line(main effect line/column color). - Default colors updated to follow the blue/red convention of the Python
shap/shapiqpackages: continuous interaction effects use a#008BFB→ white →#FF0051gradient (previously the cyclic scico palette"vikO"), andglex_explain()uses the same blue/red for negative/positive contributions.
glex 0.5.2
-
Fix newer xgboost R package compatibility:
- Updated tree schema column name from
QualitytoGain, matching xgboost commit 73713de ([R] rename Quality -> Gain (#9938), in upstream v2.1.0) - Implemented dynamic
base_scoreextraction to replace hardcoded 0.5 intercept (modern xgboost auto-estimatesbase_score) - Fixed floating-point precision mismatch in C++ split comparators by casting to float, matching xgboost predictor behavior
- Added node reindexing to ensure contiguous row ordering in tree matrices
- For CRAN users, this schema change is observed in the later 3.x package line (for example 3.1.2.1+), which requires R >= 4.3.0
- These changes ensure accurate model explanations for current CRAN xgboost releases
- Updated tree schema column name from
glex 0.5.1
- Fix path-dependent algorithm by computing the proper covers manually
- Allow
glex()to accept data frames as input
glex 0.4.2
- Optimize FastPD by only computing components up to
max_interaction(#24)
glex 0.4.1
- Added FastPD (arXiv) as default
probFunctioninglex. - Add rug plot to
plot_*_effect[s]functions for continuous predictors, defaulting to showing a rug on the bottom side (rug_side = "b").
glex 0.4.0
- Add support for ranger objects to
glex()(PR#17). - Add new optional parameter
probFunctiontoglex()which specifies the probability function for weighting/marginalization of the leaves (PR#17).
By default,glex()now uses the empirical marginal probabilities to perform the weighting. Previously, the weighting of the leaves was done based on a path-dependent method. - Add
theme_glex()as a default theme to all plots.
This is almost identical to [ggplot2::theme_minimal()] aside from increased base font size and convenience flags to toggle vertical and horizontal grid lines. - Add
subset_components()andsubset_component_names()to make it easier to extract only components belonging to a given main term. - Add pre-processed version of
Bikesharedata fromISLR2to streamlined examples. - Add
plot_pdp(), a version ofplot_main_effect()with the intercept added. - Limit
max_interactioninglex.xgb.Boostertomax_depthparameter ofxgboostmodel. Ifmax_depthis not set during model fit, the default value of6is assumed. This preventsglexfrom returning spurious higher-order interactions containing values numerically close to 0. - Extend plot functions to multiclass classification. In most cases that means facetting by the target class.
- Overhaul
glex_explainto a waterfall plot showing the SHAP decomposition for given predictors. -
autoplot.glex_vigains amax_interactionargument in line withglex_explain, and now similarly aggregates terms that either fall belowthresholdor exceedmax_interaction. - Add
glex.printfor a more compact output in case of large numbers of terms.
glex 0.3.0
- Added plotting functions for main, 2- and 3-degree interaction terms
- Added
ggplot2::autoplotS3 method forglexobjects. - Added
pkgdownsite - Added Bikesharing article
- Added
glex_vi()to compute variable importance scores including interaction terms, including a correspondingggplot2::autoplotmethod. - Added
glex_explain()to plot prediction components of a single observation.
glex 0.2.0
- Convert
glex()to an S3 generic function with methods forxgboostandrandomPlantedForestmodels. - Fix bug in
xgboostmethod that could lead to wrongly computed shap values in certain cases. - Added a
NEWS.mdfile to track changes to the package.