View source: R/tree_explainer.R
| loss | R Documentation |
This is a convenience alias for qshap_loss() that provides a shorter
function name for calculating feature-specific loss contributions.
loss(explainer, x, y, y_mean_ori = NULL)
explainer |
A qshap_tree_explainer object created by |
x |
Feature matrix or data frame |
y |
Response vector |
y_mean_ori |
Optional pre-computed mean of y (for efficiency) |
A matrix of loss contributions with dimensions (n_samples, n_features)
qshap_loss
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)
loss_matrix <- loss(explainer, X, y)
dim(loss_matrix)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.