View source: R/tree_explainer.R
| qshap | R Documentation |
This is a convenience alias for rsq() that provides a shorter
function name for calculating feature-specific R-squared values.
qshap(
explainer,
x,
y,
feature_names = NULL,
local = FALSE,
nsample = NULL,
sd_out = TRUE,
nfrac = NULL,
random_state = 42,
ncore = 1L
)
explainer |
A qshap_tree_explainer object created by |
x |
Feature matrix or data frame with n samples and p features |
y |
Response vector of length n |
feature_names |
Character vector of feature names. If NULL, uses column names from x. |
local |
Logical; if TRUE, also returns the raw observation-level
squared-loss contributions in |
nsample |
Optional integer; number of samples to use (random subsample if less than nrow(x)) |
sd_out |
Logical; if TRUE, returns standard deviations of R-squared estimates |
nfrac |
Optional numeric in (0,1); fraction of samples to use (alternative to nsample) |
random_state |
Integer seed for reproducible sampling |
ncore |
Number of cores for parallel processing. Use -1 for all available cores, or a positive integer. Default is 1 (no parallelization) |
A qshap_result object; see rsq for details.
rsq
library(xgboost)
set.seed(42)
n <- 100
p <- 100
X <- matrix(rnorm(n * p), nrow = n, ncol = p)
y <- X[, 1] - X[, 2] + rnorm(n, sd = 0.2)
model <- xgboost(X, y, nrounds = 15, max_depth = 2, verbosity = 0, nthread = 1)
explainer <- gazer(model)
phi_rsq <- qshap(explainer, X, y)
print(phi_rsq)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.