Skip to content

Commit

Permalink
[R] use predict.xgb.Booster internally when needed (#11060)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes authored Dec 5, 2024
1 parent 5be8083 commit 54930ec
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R-package/R/xgb.create.features.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
#' @export
xgb.create.features <- function(model, data, ...) {
check.deprecation(...)
pred_with_leaf <- predict(model, data, predleaf = TRUE)
pred_with_leaf <- predict.xgb.Booster(model, data, predleaf = TRUE)
cols <- lapply(as.data.frame(pred_with_leaf), factor)
cbind(data, sparse.model.matrix(~ . -1, cols)) # nolint
}
4 changes: 2 additions & 2 deletions R-package/R/xgb.plot.shap.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @param target_class Only relevant for multiclass models. The default (`NULL`)
#' averages the SHAP values over all classes. Pass a (0-based) class index
#' to show only SHAP values of that class.
#' @param approxcontrib Passed to `predict()` when `shap_contrib = NULL`.
#' @param approxcontrib Passed to [predict.xgb.Booster()] when `shap_contrib = NULL`.
#' @param subsample Fraction of data points randomly picked for plotting.
#' The default (`NULL`) will use up to 100k data points.
#' @param n_col Number of columns in a grid of plots.
Expand Down Expand Up @@ -353,7 +353,7 @@ xgb.shap.data <- function(data, shap_contrib = NULL, features = NULL, top_n = 1,
}

if (is.null(shap_contrib)) {
shap_contrib <- predict(
shap_contrib <- predict.xgb.Booster(
model,
newdata = data,
predcontrib = TRUE,
Expand Down
2 changes: 1 addition & 1 deletion R-package/man/xgb.plot.shap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion R-package/man/xgb.plot.shap.summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 54930ec

Please sign in to comment.