# \donttest{
## Friedman data
set.seed(2025)
n <- 200
p <- 5
X <- data.frame(matrix(runif(n * p), ncol = p))
y <- 10 * sin(pi* X[ ,1] * X[,2]) +20 * (X[,3] -.5)^2 + 10 * X[ ,4] + 5 * X[,5] + rnorm(n)
## Using the bartMachine
model <- bartMachine::bartMachine(X, y, seed = 2025, num_iterations_after_burn_in =200 )
## prediction wrapper function
pfun <- function (object, newdata) {
bartMachine::bart_machine_get_posterior(object,newdata) $ y_hat_posterior_samples
}
## Calculate shapley values
model_exp <- Explain ( model, X = X, pred_wrapper = pfun )
# }
Run the code above in your browser using DataLab