Repository navigation
fastshap 0.2.0
New features
- New
explain_effects()decomposes each feature's contribution into a
maineffect (the feature's effect in isolation; equal to the centered
partial dependence of that feature), atotaleffect (main effect plus
every interaction the feature participates in), and their gap
(interaction, an interaction-strength diagnostic that is exactly zero for
additive features).shapley_values(the average ofmainandtotal)
equals the exact background-marginal Shapley value for any model with at
most pairwise interactions — with no Monte Carlo simulation at all by
default, since it averages over the entire background rather than sampling
coalitions. Setnsimto sample background rows instead, for large
backgrounds where full averaging is too expensive.
Performance
-
The Monte Carlo estimation loop was rewritten to batch predictions: all
nsimreplications for a feature are now stacked and evaluated in a single
pair ofpred_wrapper()calls (previously2 * nsimcalls per feature),
letting vectorized/multithreadedpredict()methods do the heavy lifting.
Combined with the other changes below,explain()is roughly 2.5x faster
on a typical ranger example (500 x 10 data frame,nsim = 10), with much
larger gains for prediction functions with high per-call overhead. -
New
batch_sizeargument forexplain()bounds the number of rows passed
topred_wrapper()per call (memory/speed trade-off). All randomness is
drawn up front, so seeded results are identical regardless ofbatch_size. -
When
newdatais supplied, the internal permutation matrix is now generated
atnrow(newdata)instead of at the (potentially much larger) background
size and then subsampled; explaining a few rows against a large background
no longer wastes time generating discarded random rows. -
Data frame inputs are now processed column-wise instead of via matrix-style
logical indexing of data frames (one of the slowest operations in base R);
this also preserves column classes by construction, eliminating two
copy_classes()calls per Monte Carlo evaluation. -
The C++ routine that assembles the hybrid ("Frankenstein") data sets now
passes inputs by reference, skips a no-op assignment, and constructs the
second data set from the first via a single column swap (the two differ
only in the feature of interest).
Breaking changes
-
Seeded results differ from fastshap (<= 0.1.5): the Monte Carlo loop was
vectorized, which changes how the random number stream is consumed. The
estimator itself is unchanged. -
foreach moved from Imports to Suggests. Sequential execution (the
default) no longer touches foreach;parallel = TRUErequires it to be
installed and errors informatively otherwise. The dead.options.RNG
argument (only honored by%dorng%, which fastshap never used) is no longer
passed; for reproducible parallel results, register a doRNG backend. -
gen_friedman()'s deprecatedn_binsargument was removed.
Fixed
-
explain(..., parallel = TRUE)on socket-based clusters (the default
cluster type on Windows, where workers start with no packages attached)
no longer fails withcould not find function "explain_feature". The
0.2.0 batching rewrite moved the per-feature computation behind an extra
layer of internal function calls, which brokeforeach's automatic
export of the (non-exported) worker function on such clusters; the
fastshap namespace is now explicitly added to.packages. If fastshap is
installed to a non-default library path (a development checkout, an
renv/pakproject library, orR CMD check's ephemeral install), also
propagate.libPaths()to the cluster before registering it — see
?explain'sparallelargument for the one-liner. -
explain()withexact = TRUEandshap_only = TRUE(the default) for
xgb.Boosterandlgb.Boosterobjects now correctly retains the
"baseline"attribute and"explain"class; previously both were silently
dropped when the bias column was subset out of the result (the baseline
attribute was lost for both model types, and the class was also lost for
xgb.Booster). -
Unknown values in
feature_namesnow error informatively instead of
failing obscurely downstream. -
A
pred_wrapperthat does not return one prediction per row (e.g., a
multiclass probability matrix) now errors informatively instead of
producing corrupted output. -
A
tbl_dfpassed asnewdatais now coerced to a data frame (matching the
existing coercion ofX), instead of triggering a misleading class-mismatch
error.
Documentation
-
The vignette was rewritten to run in ~20 seconds (previously ~20 minutes,
which required a.Rmd.origprecompile workaround that has been removed);
it now also demonstrates the exact-vs-approximate comparison and
explain_effects()'s interaction diagnostic on the Friedman 1 benchmark
data. -
README and AGENTS.md were rewritten to match current package conventions
(branch model, dependency philosophy, architecture map).
Internal
-
Removed ~350 lines of dead code: the vendored copy of
abind()and the
copy_classes()helper (superseded by the column-wise construction). -
Dropped AmesHousing, ggplot2, and tibble from Suggests; they
were only used by the old vignette.