From 39c5f876adfe9f273e83c6d5507891486b7fe677 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 7 Jun 2023 15:44:03 +0200 Subject: [PATCH 01/10] Updating CRAN comments --- cran-comments.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index 90c84c6..156962c 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -17,20 +17,16 @@ Hello CRAN team > checking HTML version of manual ... NOTE Skipping checking HTML validation: no command 'tidy' found -### check_rhub(): Some usual notes... +### RHub * checking package dependencies ... NOTE Packages which this enhances but not available for checking: 'fastshap', 'h2o', 'lightgbm' * checking HTML version of manual ... NOTE +Skipping checking HTML validation: no command 'tidy' found Skipping checking math rendering: package 'V8' unavailable -* checking for non-standard things in the check directory ... NOTE -Found the following files/directories: - ''NULL'' -* checking for detritus in the temp directory ... NOTE -Found the following files/directories: - 'lastMiKTeXException' - -### check_win_devel() + + +### Winbuilder() Status: OK From a4602d909472cf01dc4772cb7e9653858a962708 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 7 Jun 2023 15:47:53 +0200 Subject: [PATCH 02/10] CRAN submission --- CRAN-SUBMISSION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 66ec04c..023333e 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 0.8.0 -Date: 2023-05-09 17:34:27 UTC -SHA: e2f9b361e5cb79eb0faa79faabceb98a4bd1726a +Version: 0.9.0 +Date: 2023-06-07 13:47:09 UTC +SHA: 39c5f876adfe9f273e83c6d5507891486b7fe677 From 2f8e03af92a7ced1b94139411f795dffa4f7c008 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 7 Jun 2023 16:34:31 +0200 Subject: [PATCH 03/10] Fix two typos in vignette --- vignettes/geographic.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/geographic.Rmd b/vignettes/geographic.Rmd index 9c91c4d..6814b7c 100644 --- a/vignettes/geographic.Rmd +++ b/vignettes/geographic.Rmd @@ -23,7 +23,7 @@ knitr::opts_chunk$set( ## Setting -In a model with geographic components, we want to express a functional $T$ (usually the expectation or a quantile) of a response $Y$ as a function $f$ of a set of geographic features (latitude/longitude and/or postal code and/or other features varying with location): +In a model with geographic components, we want to express a functional $T$ (usually the expectation or a quantile) of a response $Y$ as a function $f$ of a set of geographic features (latitude/longitude and/or postal code and/or other features varying with location), and other features: $$ T(Y \mid X^\textrm{geo}, X^\textrm{other}) \approx f(X^\textrm{geo}, X^\textrm{other}) @@ -34,7 +34,7 @@ That's where the additivity of SHAP values comes into play: The sum of SHAP valu ## A first example -For illustration, we will use a beautiful house price dataset containing information on about 14'000 houses sold in 2016 in Miami-Date County. Some of the columns are as follows: +For illustration, we will use a beautiful house price dataset containing information on about 14'000 houses sold in 2016 in Miami-Dade County. Some of the columns are as follows: - **SALE_PRC**: Sale price in USD: Its logarithm will be our model response. - *LATITUDE*, *LONGITUDE*: Coordinates From 66dd44a476a91e0037b7cb0b47e4c603f6169f3c Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 7 Jun 2023 17:06:12 +0200 Subject: [PATCH 04/10] resubmission --- cran-comments.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cran-comments.md b/cran-comments.md index 156962c..8bd838e 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,7 @@ +# Resubmission + +I assume the slow examples on Debian are just a hickup? + # shapviz 0.9.0 Hello CRAN team From 3ea4b7f55659195650d1074058e8f10e35ccdf59 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 7 Jun 2023 20:45:04 +0200 Subject: [PATCH 05/10] Reducing duration of examples --- CRAN-SUBMISSION | 4 ++-- R/methods.R | 2 +- R/shapviz.R | 44 ++++++++++++++++++++---------------------- R/sv_dependence.R | 14 +++++--------- R/sv_dependence2D.R | 6 +----- R/sv_force.R | 4 +--- R/sv_importance.R | 7 +------ R/sv_interaction.R | 5 ++--- R/sv_waterfall.R | 11 +---------- cran-comments.md | 5 ++++- man/shapviz.Rd | 44 ++++++++++++++++++++---------------------- man/split.shapviz.Rd | 2 +- man/sv_dependence.Rd | 14 +++++--------- man/sv_dependence2D.Rd | 6 +----- man/sv_force.Rd | 4 +--- man/sv_importance.Rd | 7 +------ man/sv_interaction.Rd | 5 ++--- man/sv_waterfall.Rd | 11 +---------- packaging.R | 2 +- 19 files changed, 73 insertions(+), 124 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 023333e..ae18b10 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.9.0 -Date: 2023-06-07 13:47:09 UTC -SHA: 39c5f876adfe9f273e83c6d5507891486b7fe677 +Date: 2023-06-07 15:08:12 UTC +SHA: 66dd44a476a91e0037b7cb0b47e4c603f6169f3c diff --git a/R/methods.R b/R/methods.R index f32f19a..7e07caa 100644 --- a/R/methods.R +++ b/R/methods.R @@ -272,7 +272,7 @@ c.shapviz <- function(...) { #' @returns A "mshapviz" object. #' @examples #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' sv <- shapviz(fit, X_pred = dtrain, X = iris) #' mx <- split(sv, f = iris$Species) #' sv_dependence(mx, "Petal.Length") diff --git a/R/shapviz.R b/R/shapviz.R index 6ec0aab..da2ed88 100644 --- a/R/shapviz.R +++ b/R/shapviz.R @@ -112,9 +112,9 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' @examples #' #' # XGBoost models -#' X_pred <- data.matrix(iris[, -1L]) -#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1L]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50L, nthread = 1L) +#' X_pred <- data.matrix(iris[, -1]) +#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1]) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' #' # Will use numeric matrix "X_pred" as feature matrix #' x <- shapviz(fit, X_pred = X_pred) @@ -129,15 +129,13 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' x <- shapviz(fit, X_pred = dtrain, X = iris) #' #' # Multiclass setting -#' params <- list(objective = "multi:softprob", num_class = 3L) -#' X_pred <- data.matrix(iris[, -5L]) -#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5L]) - 1L) -#' fit <- xgboost::xgb.train( -#' params = params, data = dtrain, nrounds = 50L, nthread = 1L -#' ) +#' params <- list(objective = "multi:softprob", num_class = 3, nthread = 1) +#' X_pred <- data.matrix(iris[, -5]) +#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5]) - 1) +#' fit <- xgboost::xgb.train(params = params, data = dtrain, nrounds = 10) #' #' # Select specific class -#' x <- shapviz(fit, X_pred = X_pred, which_class = 3L) +#' x <- shapviz(fit, X_pred = X_pred, which_class = 3) #' x #' #' # Or combine all classes to "mshapviz" object @@ -145,9 +143,9 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' x #' #' # What if we would have one-hot-encoded values and want to explain the original column? -#' X_pred <- stats::model.matrix(~ . -1, iris[, -1L]) -#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 1L])) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50L) +#' X_pred <- stats::model.matrix(~ . -1, iris[, -1]) +#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 1])) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz( #' fit, #' X_pred = X_pred, @@ -159,29 +157,29 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' # Similarly with LightGBM #' if (requireNamespace("lightgbm", quietly = TRUE)) { #' fit <- lightgbm::lgb.train( -#' params = list(objective = "regression", num_thread = 1L), -#' data = lightgbm::lgb.Dataset(X_pred, label = iris[, 1L]), -#' nrounds = 50L, -#' verbose = -2L +#' params = list(objective = "regression", num_thread = 1), +#' data = lightgbm::lgb.Dataset(X_pred, label = iris[, 1]), +#' nrounds = 10, +#' verbose = -2 #' ) #' #' x <- shapviz(fit, X_pred = X_pred) #' x #' #' # Multiclass -#' params <- list(objective = "multiclass", num_class = 3L, num_thread = 1L) -#' X_pred <- data.matrix(iris[, -5L]) -#' dtrain <- lightgbm::lgb.Dataset(X_pred, label = as.integer(iris[, 5L]) - 1L) -#' fit <- lightgbm::lgb.train(params = params, data = dtrain, nrounds = 50L) +#' params <- list(objective = "multiclass", num_class = 3, num_thread = 1) +#' X_pred <- data.matrix(iris[, -5]) +#' dtrain <- lightgbm::lgb.Dataset(X_pred, label = as.integer(iris[, 5]) - 1) +#' fit <- lightgbm::lgb.train(params = params, data = dtrain, nrounds = 10) #' #' # Select specific class -#' x <- shapviz(fit, X_pred = X_pred, which_class = 3L) +#' x <- shapviz(fit, X_pred = X_pred, which_class = 3) #' x #' #' # Or combine all classes to a "mshapviz" object #' mx <- shapviz(fit, X_pred = X_pred) #' mx -#' all.equal(mx[[3L]], x) +#' all.equal(mx[[3]], x) #' } shapviz.xgb.Booster = function(object, X_pred, X = X_pred, which_class = NULL, collapse = NULL, interactions = FALSE, ...) { diff --git a/R/sv_dependence.R b/R/sv_dependence.R index fb15f82..93bc2af 100644 --- a/R/sv_dependence.R +++ b/R/sv_dependence.R @@ -35,7 +35,7 @@ #' @returns An object of class "ggplot" (or "patchwork") representing a dependence plot. #' @examples #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris) #' sv_dependence(x, "Petal.Length") #' sv_dependence(x, "Petal.Length", color_var = "Species") @@ -43,17 +43,13 @@ #' sv_dependence(x, c("Species", "Petal.Length")) #' sv_dependence(x, "Petal.Width", color_var = c("Species", "Petal.Length")) #' -#' # SHAP interaction values +#' # SHAP interaction values/main effects #' x2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) #' sv_dependence(x2, "Petal.Length", interactions = TRUE) -#' sv_dependence(x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE) -#' -#' # Show main effect of "Petal.Length" for setosa and virginica separately -#' mx <- c( -#' setosa = x2[x2$X$Species == "setosa"], -#' virginica = x2[x2$X$Species == "virginica"] +#' sv_dependence( +#' x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE #' ) -#' sv_dependence(mx, "Petal.Length", color_var = NULL, interactions = TRUE) +#' #' @export #' @seealso [potential_interactions()] sv_dependence <- function(object, ...) { diff --git a/R/sv_dependence2D.R b/R/sv_dependence2D.R index d7d6167..0e88fc6 100644 --- a/R/sv_dependence2D.R +++ b/R/sv_dependence2D.R @@ -29,14 +29,10 @@ #' @returns An object of class "ggplot" (or "patchwork") representing a dependence plot. #' @examples #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' sv <- shapviz(fit, X_pred = dtrain, X = iris) #' sv_dependence2D(sv, x = "Petal.Length", y = "Species") -#' sv_dependence2D(sv, x = "Petal.Length", y = "Sepal.Width") #' sv_dependence2D(sv, x = c("Petal.Length", "Species"), y = "Sepal.Width") -#' sv_dependence2D( -#' sv, x = c("Petal.Length", "Species"), y = c("Petal.Width", "Sepal.Width") -#' ) #' #' # SHAP interaction values #' sv2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) diff --git a/R/sv_force.R b/R/sv_force.R index 6d99b11..27bf1c8 100644 --- a/R/sv_force.R +++ b/R/sv_force.R @@ -12,7 +12,7 @@ #' @returns An object of class "ggplot" (or "patchwork") representing a force plot. #' @examples #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) #' sv_force(x) #' sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5) @@ -20,8 +20,6 @@ #' # Aggregate over all observations with Petal.Length == 1.4 #' sv_force(x, row_id = x$X$Petal.Length == 1.4) #' -#' # Combine two force plots via {patchwork} -#' sv_force(c(Obs1 = x[1], Obs2 = x[2])) #' @export #' @seealso [sv_waterfall()] sv_force <- function(object, ...) { diff --git a/R/sv_importance.R b/R/sv_importance.R index 1e9f2fe..50452a8 100644 --- a/R/sv_importance.R +++ b/R/sv_importance.R @@ -44,17 +44,12 @@ #' @examples #' X_train <- data.matrix(iris[, -1]) #' dtrain <- xgboost::xgb.DMatrix(X_train, label = iris[, 1]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = X_train) #' sv_importance(x) #' sv_importance(x, kind = "beeswarm", show_numbers = TRUE) #' sv_importance(x, kind = "no") #' -#' X <- data.frame(matrix(rnorm(1000), ncol = 20)) -#' S <- as.matrix(X) -#' x2 <- shapviz(S, X) -#' sv_importance(x2) -#' sv_importance(x2, max_display = 5) #' @seealso \code{\link{sv_interaction}} #' @export sv_importance <- function(object, ...) { diff --git a/R/sv_interaction.R b/R/sv_interaction.R index 8f2f489..d77301c 100644 --- a/R/sv_interaction.R +++ b/R/sv_interaction.R @@ -19,10 +19,9 @@ #' absolute SHAP values (or a list of such matrices in case of "mshapviz" object). #' @examples #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) -#' sv_interaction(x) -#' sv_interaction(x, max_display = 2, size = 3, alpha = 0.1) +#' sv_interaction(x, max_display = 2, size = 3) #' sv_interaction(x, kind = "no") #' @seealso [sv_importance()] #' @export diff --git a/R/sv_waterfall.R b/R/sv_waterfall.R index 0222053..0eeb560 100644 --- a/R/sv_waterfall.R +++ b/R/sv_waterfall.R @@ -36,7 +36,7 @@ #' @returns An object of class "ggplot" (or "patchwork") representing a waterfall plot. #' @examples #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) #' sv_waterfall(x) #' sv_waterfall(x, row_id = 123, max_display = 2, size = 9, fill_colors = 4:5) @@ -49,15 +49,6 @@ #' # Aggregate over all observations with Petal.Length == 1.4 #' sv_waterfall(x, row_id = x$X$Petal.Length == 1.4) #' -#' # More features -#' X <- as.data.frame(matrix(1:100, nrow = 10)) -#' S <- as.matrix(X) -#' shp <- shapviz(S, X) -#' sv_waterfall(shp) -#' -#' # Combine two waterfall plots via {patchwork} -#' sv_waterfall(c(Obs1 = x[1], Obs2 = x[2])) + -#' patchwork::plot_layout(ncol = 1) #' @export #' @seealso [sv_force()] sv_waterfall <- function(object, ...) { diff --git a/cran-comments.md b/cran-comments.md index 8bd838e..9151258 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,6 +1,9 @@ # Resubmission -I assume the slow examples on Debian are just a hickup? +Examples taking too long on Linux. + +- I have now reduced the number of examples. +- And the number of boosting rounds. # shapviz 0.9.0 diff --git a/man/shapviz.Rd b/man/shapviz.Rd index da5c9b6..679c291 100644 --- a/man/shapviz.Rd +++ b/man/shapviz.Rd @@ -170,9 +170,9 @@ X <- data.frame(x = c("a", "b"), y = c(100, 10)) shapviz(S, X, baseline = 4) # XGBoost models -X_pred <- data.matrix(iris[, -1L]) -dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1L]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50L, nthread = 1L) +X_pred <- data.matrix(iris[, -1]) +dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1]) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) # Will use numeric matrix "X_pred" as feature matrix x <- shapviz(fit, X_pred = X_pred) @@ -187,15 +187,13 @@ sv_dependence(x, "Species") x <- shapviz(fit, X_pred = dtrain, X = iris) # Multiclass setting -params <- list(objective = "multi:softprob", num_class = 3L) -X_pred <- data.matrix(iris[, -5L]) -dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5L]) - 1L) -fit <- xgboost::xgb.train( - params = params, data = dtrain, nrounds = 50L, nthread = 1L -) +params <- list(objective = "multi:softprob", num_class = 3, nthread = 1) +X_pred <- data.matrix(iris[, -5]) +dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5]) - 1) +fit <- xgboost::xgb.train(params = params, data = dtrain, nrounds = 10) # Select specific class -x <- shapviz(fit, X_pred = X_pred, which_class = 3L) +x <- shapviz(fit, X_pred = X_pred, which_class = 3) x # Or combine all classes to "mshapviz" object @@ -203,9 +201,9 @@ x <- shapviz(fit, X_pred = X_pred) x # What if we would have one-hot-encoded values and want to explain the original column? -X_pred <- stats::model.matrix(~ . -1, iris[, -1L]) -dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 1L])) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50L) +X_pred <- stats::model.matrix(~ . -1, iris[, -1]) +dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 1])) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz( fit, X_pred = X_pred, @@ -217,29 +215,29 @@ summary(x) # Similarly with LightGBM if (requireNamespace("lightgbm", quietly = TRUE)) { fit <- lightgbm::lgb.train( - params = list(objective = "regression", num_thread = 1L), - data = lightgbm::lgb.Dataset(X_pred, label = iris[, 1L]), - nrounds = 50L, - verbose = -2L + params = list(objective = "regression", num_thread = 1), + data = lightgbm::lgb.Dataset(X_pred, label = iris[, 1]), + nrounds = 10, + verbose = -2 ) x <- shapviz(fit, X_pred = X_pred) x # Multiclass - params <- list(objective = "multiclass", num_class = 3L, num_thread = 1L) - X_pred <- data.matrix(iris[, -5L]) - dtrain <- lightgbm::lgb.Dataset(X_pred, label = as.integer(iris[, 5L]) - 1L) - fit <- lightgbm::lgb.train(params = params, data = dtrain, nrounds = 50L) + params <- list(objective = "multiclass", num_class = 3, num_thread = 1) + X_pred <- data.matrix(iris[, -5]) + dtrain <- lightgbm::lgb.Dataset(X_pred, label = as.integer(iris[, 5]) - 1) + fit <- lightgbm::lgb.train(params = params, data = dtrain, nrounds = 10) # Select specific class - x <- shapviz(fit, X_pred = X_pred, which_class = 3L) + x <- shapviz(fit, X_pred = X_pred, which_class = 3) x # Or combine all classes to a "mshapviz" object mx <- shapviz(fit, X_pred = X_pred) mx - all.equal(mx[[3L]], x) + all.equal(mx[[3]], x) } } \seealso{ diff --git a/man/split.shapviz.Rd b/man/split.shapviz.Rd index eb0e527..55a0cb2 100644 --- a/man/split.shapviz.Rd +++ b/man/split.shapviz.Rd @@ -21,7 +21,7 @@ Splits "shapviz" object along a vector \code{f} into an object of class "mshapvi } \examples{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) sv <- shapviz(fit, X_pred = dtrain, X = iris) mx <- split(sv, f = iris$Species) sv_dependence(mx, "Petal.Length") diff --git a/man/sv_dependence.Rd b/man/sv_dependence.Rd index 283c1b1..6b40d8d 100644 --- a/man/sv_dependence.Rd +++ b/man/sv_dependence.Rd @@ -87,7 +87,7 @@ to focus on pure interaction effects (multiplied by two) or on pure main effects }} \examples{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris) sv_dependence(x, "Petal.Length") sv_dependence(x, "Petal.Length", color_var = "Species") @@ -95,17 +95,13 @@ sv_dependence(x, "Petal.Length", color_var = NULL) sv_dependence(x, c("Species", "Petal.Length")) sv_dependence(x, "Petal.Width", color_var = c("Species", "Petal.Length")) -# SHAP interaction values +# SHAP interaction values/main effects x2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) sv_dependence(x2, "Petal.Length", interactions = TRUE) -sv_dependence(x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE) - -# Show main effect of "Petal.Length" for setosa and virginica separately -mx <- c( - setosa = x2[x2$X$Species == "setosa"], - virginica = x2[x2$X$Species == "virginica"] +sv_dependence( + x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE ) -sv_dependence(mx, "Petal.Length", color_var = NULL, interactions = TRUE) + } \seealso{ \code{\link[=potential_interactions]{potential_interactions()}} diff --git a/man/sv_dependence2D.Rd b/man/sv_dependence2D.Rd index e8170ce..b11d4b8 100644 --- a/man/sv_dependence2D.Rd +++ b/man/sv_dependence2D.Rd @@ -94,14 +94,10 @@ to focus on pure interaction effects (multiplied by two). }} \examples{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) sv <- shapviz(fit, X_pred = dtrain, X = iris) sv_dependence2D(sv, x = "Petal.Length", y = "Species") -sv_dependence2D(sv, x = "Petal.Length", y = "Sepal.Width") sv_dependence2D(sv, x = c("Petal.Length", "Species"), y = "Sepal.Width") -sv_dependence2D( - sv, x = c("Petal.Length", "Species"), y = c("Petal.Width", "Sepal.Width") -) # SHAP interaction values sv2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) diff --git a/man/sv_force.Rd b/man/sv_force.Rd index bc1079c..4a2fb84 100644 --- a/man/sv_force.Rd +++ b/man/sv_force.Rd @@ -97,7 +97,7 @@ baseline SHAP value. }} \examples{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) sv_force(x) sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5) @@ -105,8 +105,6 @@ sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5) # Aggregate over all observations with Petal.Length == 1.4 sv_force(x, row_id = x$X$Petal.Length == 1.4) -# Combine two force plots via {patchwork} -sv_force(c(Obs1 = x[1], Obs2 = x[2])) } \seealso{ \code{\link[=sv_waterfall]{sv_waterfall()}} diff --git a/man/sv_importance.Rd b/man/sv_importance.Rd index cbb026d..05512a1 100644 --- a/man/sv_importance.Rd +++ b/man/sv_importance.Rd @@ -113,17 +113,12 @@ are sorted in decreasing order of importance. \examples{ X_train <- data.matrix(iris[, -1]) dtrain <- xgboost::xgb.DMatrix(X_train, label = iris[, 1]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = X_train) sv_importance(x) sv_importance(x, kind = "beeswarm", show_numbers = TRUE) sv_importance(x, kind = "no") -X <- data.frame(matrix(rnorm(1000), ncol = 20)) -S <- as.matrix(X) -x2 <- shapviz(S, X) -sv_importance(x2) -sv_importance(x2, max_display = 5) } \seealso{ \code{\link{sv_interaction}} diff --git a/man/sv_interaction.Rd b/man/sv_interaction.Rd index 37660aa..bfc3ff5 100644 --- a/man/sv_interaction.Rd +++ b/man/sv_interaction.Rd @@ -88,10 +88,9 @@ The features are sorted in decreasing order of usual SHAP importance. }} \examples{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) -sv_interaction(x) -sv_interaction(x, max_display = 2, size = 3, alpha = 0.1) +sv_interaction(x, max_display = 2, size = 3) sv_interaction(x, kind = "no") } \seealso{ diff --git a/man/sv_waterfall.Rd b/man/sv_waterfall.Rd index 48b87f1..6238e3b 100644 --- a/man/sv_waterfall.Rd +++ b/man/sv_waterfall.Rd @@ -103,7 +103,7 @@ baseline SHAP value. }} \examples{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) -fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1) +fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) sv_waterfall(x) sv_waterfall(x, row_id = 123, max_display = 2, size = 9, fill_colors = 4:5) @@ -116,15 +116,6 @@ sv_waterfall( # Aggregate over all observations with Petal.Length == 1.4 sv_waterfall(x, row_id = x$X$Petal.Length == 1.4) -# More features -X <- as.data.frame(matrix(1:100, nrow = 10)) -S <- as.matrix(X) -shp <- shapviz(S, X) -sv_waterfall(shp) - -# Combine two waterfall plots via {patchwork} -sv_waterfall(c(Obs1 = x[1], Obs2 = x[2])) + - patchwork::plot_layout(ncol = 1) } \seealso{ \code{\link[=sv_force]{sv_force()}} diff --git a/packaging.R b/packaging.R index 1a5681f..8ce1bdb 100644 --- a/packaging.R +++ b/packaging.R @@ -101,7 +101,7 @@ library(devtools) document() test() -check(manual = TRUE, cran = TRUE, vignettes = TRUE) +check(manual = TRUE, cran = TRUE, vignettes = FALSE) build() # build(binary = TRUE) install(upgrade = FALSE) From 4a16a8993ddfa8b52ef72d3e0056901c2702fa37 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 7 Jun 2023 20:49:12 +0200 Subject: [PATCH 06/10] Resubmission --- CRAN-SUBMISSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index ae18b10..07e0368 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.9.0 -Date: 2023-06-07 15:08:12 UTC -SHA: 66dd44a476a91e0037b7cb0b47e4c603f6169f3c +Date: 2023-06-07 18:48:23 UTC +SHA: 3ea4b7f55659195650d1074058e8f10e35ccdf59 From 11506767b515bf872e0a1fbee5426bd6cba1aea5 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Thu, 8 Jun 2023 14:43:22 +0200 Subject: [PATCH 07/10] Check for Linux debian --- packaging.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging.R b/packaging.R index 8ce1bdb..4f3ddec 100644 --- a/packaging.R +++ b/packaging.R @@ -109,7 +109,7 @@ install(upgrade = FALSE) # Run only if package is public(!) and should go to CRAN if (FALSE) { check_win_devel() - check_rhub() + check_rhub(platforms = "debian-gcc-devel") # Wait until above checks are passed without relevant notes/warnings # then submit to CRAN From 32c5b1b9f2576d24d1522daf2f62df6cb41ad6a2 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Thu, 8 Jun 2023 20:18:19 +0200 Subject: [PATCH 08/10] Adding dont runs --- CRAN-SUBMISSION | 4 ++-- R/shapviz.R | 2 ++ R/sv_dependence.R | 3 ++- R/sv_dependence2D.R | 2 ++ R/sv_force.R | 4 +++- R/sv_importance.R | 5 ++++- R/sv_interaction.R | 5 ++++- R/sv_waterfall.R | 3 ++- cran-comments.md | 4 ++++ man/shapviz.Rd | 2 ++ man/sv_dependence.Rd | 3 ++- man/sv_dependence2D.Rd | 2 ++ man/sv_force.Rd | 4 +++- man/sv_importance.Rd | 5 ++++- man/sv_interaction.Rd | 5 ++++- man/sv_waterfall.Rd | 3 ++- 16 files changed, 44 insertions(+), 12 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 07e0368..7fbbb37 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.9.0 -Date: 2023-06-07 18:48:23 UTC -SHA: 3ea4b7f55659195650d1074058e8f10e35ccdf59 +Date: 2023-06-08 12:47:01 UTC +SHA: 11506767b515bf872e0a1fbee5426bd6cba1aea5 diff --git a/R/shapviz.R b/R/shapviz.R index da2ed88..0cc686a 100644 --- a/R/shapviz.R +++ b/R/shapviz.R @@ -128,6 +128,7 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' # "X_pred" can also be passed as xgb.DMatrix, but only if X is passed as well! #' x <- shapviz(fit, X_pred = dtrain, X = iris) #' +#' \dontrun{ #' # Multiclass setting #' params <- list(objective = "multi:softprob", num_class = 3, nthread = 1) #' X_pred <- data.matrix(iris[, -5]) @@ -153,6 +154,7 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' collapse = list(Species = c("Speciessetosa", "Speciesversicolor", "Speciesvirginica")) #' ) #' summary(x) +#' } #' #' # Similarly with LightGBM #' if (requireNamespace("lightgbm", quietly = TRUE)) { diff --git a/R/sv_dependence.R b/R/sv_dependence.R index 93bc2af..850e9a4 100644 --- a/R/sv_dependence.R +++ b/R/sv_dependence.R @@ -43,13 +43,14 @@ #' sv_dependence(x, c("Species", "Petal.Length")) #' sv_dependence(x, "Petal.Width", color_var = c("Species", "Petal.Length")) #' +#' \dontrun{ #' # SHAP interaction values/main effects #' x2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) #' sv_dependence(x2, "Petal.Length", interactions = TRUE) #' sv_dependence( #' x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE #' ) -#' +#' } #' @export #' @seealso [potential_interactions()] sv_dependence <- function(object, ...) { diff --git a/R/sv_dependence2D.R b/R/sv_dependence2D.R index 0e88fc6..83997bb 100644 --- a/R/sv_dependence2D.R +++ b/R/sv_dependence2D.R @@ -34,6 +34,7 @@ #' sv_dependence2D(sv, x = "Petal.Length", y = "Species") #' sv_dependence2D(sv, x = c("Petal.Length", "Species"), y = "Sepal.Width") #' +#' \dontrun{ #' # SHAP interaction values #' sv2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) #' sv_dependence2D(sv2, x = "Petal.Length", y = "Species", interactions = TRUE) @@ -44,6 +45,7 @@ #' # mshapviz object #' mx <- split(sv, f = iris$Species) #' sv_dependence2D(mx, x = "Petal.Length", y = "Sepal.Width") +#' } #' @export #' @seealso [sv_dependence()] sv_dependence2D <- function(object, ...) { diff --git a/R/sv_force.R b/R/sv_force.R index 27bf1c8..9f12805 100644 --- a/R/sv_force.R +++ b/R/sv_force.R @@ -15,11 +15,13 @@ #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) #' sv_force(x) +#' +#' \dontrun{ #' sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5) #' #' # Aggregate over all observations with Petal.Length == 1.4 #' sv_force(x, row_id = x$X$Petal.Length == 1.4) -#' +#' } #' @export #' @seealso [sv_waterfall()] sv_force <- function(object, ...) { diff --git a/R/sv_importance.R b/R/sv_importance.R index 50452a8..54a3bd8 100644 --- a/R/sv_importance.R +++ b/R/sv_importance.R @@ -47,9 +47,12 @@ #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = X_train) #' sv_importance(x) -#' sv_importance(x, kind = "beeswarm", show_numbers = TRUE) #' sv_importance(x, kind = "no") #' +#' \dontrun{ +#' sv_importance(x, kind = "beeswarm", show_numbers = TRUE) +#' } +#' #' @seealso \code{\link{sv_interaction}} #' @export sv_importance <- function(object, ...) { diff --git a/R/sv_interaction.R b/R/sv_interaction.R index d77301c..5fc94c0 100644 --- a/R/sv_interaction.R +++ b/R/sv_interaction.R @@ -21,8 +21,11 @@ #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) -#' sv_interaction(x, max_display = 2, size = 3) #' sv_interaction(x, kind = "no") +#' +#' \dontrun{ +#' sv_interaction(x, max_display = 2, size = 3) +#' } #' @seealso [sv_importance()] #' @export sv_interaction <- function(object, ...) { diff --git a/R/sv_waterfall.R b/R/sv_waterfall.R index 0eeb560..4eae34e 100644 --- a/R/sv_waterfall.R +++ b/R/sv_waterfall.R @@ -41,6 +41,7 @@ #' sv_waterfall(x) #' sv_waterfall(x, row_id = 123, max_display = 2, size = 9, fill_colors = 4:5) #' +#' \dontrun{ #' # Ordered by colnames(x), combined with max_display #' sv_waterfall( #' x[, sort(colnames(x))], order_fun = function(s) length(s):1, max_display = 3 @@ -48,7 +49,7 @@ #' #' # Aggregate over all observations with Petal.Length == 1.4 #' sv_waterfall(x, row_id = x$X$Petal.Length == 1.4) -#' +#' } #' @export #' @seealso [sv_force()] sv_waterfall <- function(object, ...) { diff --git a/cran-comments.md b/cran-comments.md index 9151258..67fe31f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,7 @@ +# Re-resubmission + +Examples still taking too long on Linux. No idea how to fix this except using dontruns... + # Resubmission Examples taking too long on Linux. diff --git a/man/shapviz.Rd b/man/shapviz.Rd index 679c291..73a564f 100644 --- a/man/shapviz.Rd +++ b/man/shapviz.Rd @@ -186,6 +186,7 @@ sv_dependence(x, "Species") # "X_pred" can also be passed as xgb.DMatrix, but only if X is passed as well! x <- shapviz(fit, X_pred = dtrain, X = iris) +\dontrun{ # Multiclass setting params <- list(objective = "multi:softprob", num_class = 3, nthread = 1) X_pred <- data.matrix(iris[, -5]) @@ -211,6 +212,7 @@ x <- shapviz( collapse = list(Species = c("Speciessetosa", "Speciesversicolor", "Speciesvirginica")) ) summary(x) +} # Similarly with LightGBM if (requireNamespace("lightgbm", quietly = TRUE)) { diff --git a/man/sv_dependence.Rd b/man/sv_dependence.Rd index 6b40d8d..44487e5 100644 --- a/man/sv_dependence.Rd +++ b/man/sv_dependence.Rd @@ -95,13 +95,14 @@ sv_dependence(x, "Petal.Length", color_var = NULL) sv_dependence(x, c("Species", "Petal.Length")) sv_dependence(x, "Petal.Width", color_var = c("Species", "Petal.Length")) +\dontrun{ # SHAP interaction values/main effects x2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) sv_dependence(x2, "Petal.Length", interactions = TRUE) sv_dependence( x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE ) - +} } \seealso{ \code{\link[=potential_interactions]{potential_interactions()}} diff --git a/man/sv_dependence2D.Rd b/man/sv_dependence2D.Rd index b11d4b8..bc62eff 100644 --- a/man/sv_dependence2D.Rd +++ b/man/sv_dependence2D.Rd @@ -99,6 +99,7 @@ sv <- shapviz(fit, X_pred = dtrain, X = iris) sv_dependence2D(sv, x = "Petal.Length", y = "Species") sv_dependence2D(sv, x = c("Petal.Length", "Species"), y = "Sepal.Width") +\dontrun{ # SHAP interaction values sv2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) sv_dependence2D(sv2, x = "Petal.Length", y = "Species", interactions = TRUE) @@ -110,6 +111,7 @@ sv_dependence2D( mx <- split(sv, f = iris$Species) sv_dependence2D(mx, x = "Petal.Length", y = "Sepal.Width") } +} \seealso{ \code{\link[=sv_dependence]{sv_dependence()}} } diff --git a/man/sv_force.Rd b/man/sv_force.Rd index 4a2fb84..1881cf3 100644 --- a/man/sv_force.Rd +++ b/man/sv_force.Rd @@ -100,11 +100,13 @@ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) sv_force(x) + +\dontrun{ sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5) # Aggregate over all observations with Petal.Length == 1.4 sv_force(x, row_id = x$X$Petal.Length == 1.4) - +} } \seealso{ \code{\link[=sv_waterfall]{sv_waterfall()}} diff --git a/man/sv_importance.Rd b/man/sv_importance.Rd index 05512a1..402b148 100644 --- a/man/sv_importance.Rd +++ b/man/sv_importance.Rd @@ -116,9 +116,12 @@ dtrain <- xgboost::xgb.DMatrix(X_train, label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = X_train) sv_importance(x) -sv_importance(x, kind = "beeswarm", show_numbers = TRUE) sv_importance(x, kind = "no") +\dontrun{ +sv_importance(x, kind = "beeswarm", show_numbers = TRUE) +} + } \seealso{ \code{\link{sv_interaction}} diff --git a/man/sv_interaction.Rd b/man/sv_interaction.Rd index bfc3ff5..b889818 100644 --- a/man/sv_interaction.Rd +++ b/man/sv_interaction.Rd @@ -90,8 +90,11 @@ The features are sorted in decreasing order of usual SHAP importance. dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) -sv_interaction(x, max_display = 2, size = 3) sv_interaction(x, kind = "no") + +\dontrun{ +sv_interaction(x, max_display = 2, size = 3) +} } \seealso{ \code{\link[=sv_importance]{sv_importance()}} diff --git a/man/sv_waterfall.Rd b/man/sv_waterfall.Rd index 6238e3b..987af0a 100644 --- a/man/sv_waterfall.Rd +++ b/man/sv_waterfall.Rd @@ -108,6 +108,7 @@ x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) sv_waterfall(x) sv_waterfall(x, row_id = 123, max_display = 2, size = 9, fill_colors = 4:5) +\dontrun{ # Ordered by colnames(x), combined with max_display sv_waterfall( x[, sort(colnames(x))], order_fun = function(s) length(s):1, max_display = 3 @@ -115,7 +116,7 @@ sv_waterfall( # Aggregate over all observations with Petal.Length == 1.4 sv_waterfall(x, row_id = x$X$Petal.Length == 1.4) - +} } \seealso{ \code{\link[=sv_force]{sv_force()}} From 3f6bd1f781851c169a080adb317142b133f58147 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 9 Jun 2023 16:14:01 +0200 Subject: [PATCH 09/10] more dontruns --- CRAN-SUBMISSION | 4 ++-- R/methods.R | 2 ++ R/shapviz.R | 7 +++---- R/sv_dependence.R | 2 +- R/sv_dependence2D.R | 2 +- R/sv_force.R | 3 +-- R/sv_importance.R | 3 +-- R/sv_interaction.R | 3 +-- R/sv_waterfall.R | 2 +- cran-comments.md | 10 +++++----- man/shapviz.Rd | 7 +++---- man/split.shapviz.Rd | 2 ++ man/sv_dependence.Rd | 2 +- man/sv_dependence2D.Rd | 2 +- man/sv_force.Rd | 3 +-- man/sv_importance.Rd | 3 +-- man/sv_interaction.Rd | 3 +-- man/sv_waterfall.Rd | 2 +- 18 files changed, 29 insertions(+), 33 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 7fbbb37..cebaeb2 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.9.0 -Date: 2023-06-08 12:47:01 UTC -SHA: 11506767b515bf872e0a1fbee5426bd6cba1aea5 +Date: 2023-06-08 18:22:09 UTC +SHA: 32c5b1b9f2576d24d1522daf2f62df6cb41ad6a2 diff --git a/R/methods.R b/R/methods.R index 7e07caa..8b778e6 100644 --- a/R/methods.R +++ b/R/methods.R @@ -271,11 +271,13 @@ c.shapviz <- function(...) { #' @param ... Arguments passed to `split()`. #' @returns A "mshapviz" object. #' @examples +#' \dontrun{ #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' sv <- shapviz(fit, X_pred = dtrain, X = iris) #' mx <- split(sv, f = iris$Species) #' sv_dependence(mx, "Petal.Length") +#' } #' @export #' @seealso [shapviz()], [rbind.shapviz()] split.shapviz <- function(x, f, ...) { diff --git a/R/shapviz.R b/R/shapviz.R index 0cc686a..e1f61a2 100644 --- a/R/shapviz.R +++ b/R/shapviz.R @@ -63,7 +63,7 @@ #' scale of the SHAP values. #' - `S_inter`: Numeric array of SHAP interaction values (or `NULL`). #' @seealso -#' [sv_importance()], [sv_dependence()], [sv_interaction()], +#' [sv_importance()], [sv_dependence()], [sv_dependence2D()], [sv_interaction()], #' [sv_waterfall()], [sv_force()], [collapse_shap()] #' @examples #' S <- matrix(c(1, -1, -1, 1), ncol = 2, dimnames = list(NULL, c("x", "y"))) @@ -110,7 +110,7 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' Creates a "shapviz" object from an XGBoost model. #' @export #' @examples -#' +#' \dontrun{ #' # XGBoost models #' X_pred <- data.matrix(iris[, -1]) #' dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1]) @@ -128,7 +128,6 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' # "X_pred" can also be passed as xgb.DMatrix, but only if X is passed as well! #' x <- shapviz(fit, X_pred = dtrain, X = iris) #' -#' \dontrun{ #' # Multiclass setting #' params <- list(objective = "multi:softprob", num_class = 3, nthread = 1) #' X_pred <- data.matrix(iris[, -5]) @@ -154,7 +153,6 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' collapse = list(Species = c("Speciessetosa", "Speciesversicolor", "Speciesvirginica")) #' ) #' summary(x) -#' } #' #' # Similarly with LightGBM #' if (requireNamespace("lightgbm", quietly = TRUE)) { @@ -183,6 +181,7 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL, #' mx #' all.equal(mx[[3]], x) #' } +#' } shapviz.xgb.Booster = function(object, X_pred, X = X_pred, which_class = NULL, collapse = NULL, interactions = FALSE, ...) { stopifnot( diff --git a/R/sv_dependence.R b/R/sv_dependence.R index 850e9a4..20e7c2d 100644 --- a/R/sv_dependence.R +++ b/R/sv_dependence.R @@ -34,6 +34,7 @@ #' @param ... Arguments passed to [ggplot2::geom_jitter()]. #' @returns An object of class "ggplot" (or "patchwork") representing a dependence plot. #' @examples +#' \dontrun{ #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris) @@ -43,7 +44,6 @@ #' sv_dependence(x, c("Species", "Petal.Length")) #' sv_dependence(x, "Petal.Width", color_var = c("Species", "Petal.Length")) #' -#' \dontrun{ #' # SHAP interaction values/main effects #' x2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) #' sv_dependence(x2, "Petal.Length", interactions = TRUE) diff --git a/R/sv_dependence2D.R b/R/sv_dependence2D.R index 83997bb..6f1e6f6 100644 --- a/R/sv_dependence2D.R +++ b/R/sv_dependence2D.R @@ -28,13 +28,13 @@ #' @param ... Arguments passed to [ggplot2::geom_jitter()]. #' @returns An object of class "ggplot" (or "patchwork") representing a dependence plot. #' @examples +#' \dontrun{ #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' sv <- shapviz(fit, X_pred = dtrain, X = iris) #' sv_dependence2D(sv, x = "Petal.Length", y = "Species") #' sv_dependence2D(sv, x = c("Petal.Length", "Species"), y = "Sepal.Width") #' -#' \dontrun{ #' # SHAP interaction values #' sv2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) #' sv_dependence2D(sv2, x = "Petal.Length", y = "Species", interactions = TRUE) diff --git a/R/sv_force.R b/R/sv_force.R index 9f12805..1d8a463 100644 --- a/R/sv_force.R +++ b/R/sv_force.R @@ -11,12 +11,11 @@ #' (via [ggrepel::geom_text_repel()]). #' @returns An object of class "ggplot" (or "patchwork") representing a force plot. #' @examples +#' \dontrun{ #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) #' sv_force(x) -#' -#' \dontrun{ #' sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5) #' #' # Aggregate over all observations with Petal.Length == 1.4 diff --git a/R/sv_importance.R b/R/sv_importance.R index 54a3bd8..fd53c65 100644 --- a/R/sv_importance.R +++ b/R/sv_importance.R @@ -42,14 +42,13 @@ #' `kind = "no"` - a named numeric vector of sorted SHAP feature importances #' (or a list of such vectors in case of an object of class "mshapviz"). #' @examples +#' \dontrun{ #' X_train <- data.matrix(iris[, -1]) #' dtrain <- xgboost::xgb.DMatrix(X_train, label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = X_train) #' sv_importance(x) #' sv_importance(x, kind = "no") -#' -#' \dontrun{ #' sv_importance(x, kind = "beeswarm", show_numbers = TRUE) #' } #' diff --git a/R/sv_interaction.R b/R/sv_interaction.R index 5fc94c0..36c30d4 100644 --- a/R/sv_interaction.R +++ b/R/sv_interaction.R @@ -18,12 +18,11 @@ #' numeric matrix of average absolute SHAP interactions sorted by the average #' absolute SHAP values (or a list of such matrices in case of "mshapviz" object). #' @examples +#' \dontrun{ #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) #' sv_interaction(x, kind = "no") -#' -#' \dontrun{ #' sv_interaction(x, max_display = 2, size = 3) #' } #' @seealso [sv_importance()] diff --git a/R/sv_waterfall.R b/R/sv_waterfall.R index 4eae34e..21e8783 100644 --- a/R/sv_waterfall.R +++ b/R/sv_waterfall.R @@ -35,13 +35,13 @@ #' will altogether suppress adding text to the bars. #' @returns An object of class "ggplot" (or "patchwork") representing a waterfall plot. #' @examples +#' \dontrun{ #' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) #' fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) #' x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) #' sv_waterfall(x) #' sv_waterfall(x, row_id = 123, max_display = 2, size = 9, fill_colors = 4:5) #' -#' \dontrun{ #' # Ordered by colnames(x), combined with max_display #' sv_waterfall( #' x[, sort(colnames(x))], order_fun = function(s) length(s):1, max_display = 3 diff --git a/cran-comments.md b/cran-comments.md index 67fe31f..c1cd7fe 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,5 +1,9 @@ # Re-resubmission +Examples that take 0.09 seconds on my Windows laptop take 6 seconds on Linux. I don't know how to fix this, so I am resorting to dontruns around all examples involving XGBoost. + +# Re-resubmission + Examples still taking too long on Linux. No idea how to fix this except using dontruns... # Resubmission @@ -19,11 +23,7 @@ Hello CRAN team ## Checks look good -### check(manual = TRUE, cran = TRUE) - -> checking data for ASCII and uncompressed saves ... OK - WARNING - 'qpdf' is needed for checks on size reduction of PDFs +### check(manual = TRUE, cran = TRUE) > checking HTML version of manual ... NOTE Skipping checking HTML validation: no command 'tidy' found diff --git a/man/shapviz.Rd b/man/shapviz.Rd index 73a564f..3ef9642 100644 --- a/man/shapviz.Rd +++ b/man/shapviz.Rd @@ -168,7 +168,7 @@ return a "mshapviz" object, containing a "shapviz" object per output. S <- matrix(c(1, -1, -1, 1), ncol = 2, dimnames = list(NULL, c("x", "y"))) X <- data.frame(x = c("a", "b"), y = c(100, 10)) shapviz(S, X, baseline = 4) - +\dontrun{ # XGBoost models X_pred <- data.matrix(iris[, -1]) dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1]) @@ -186,7 +186,6 @@ sv_dependence(x, "Species") # "X_pred" can also be passed as xgb.DMatrix, but only if X is passed as well! x <- shapviz(fit, X_pred = dtrain, X = iris) -\dontrun{ # Multiclass setting params <- list(objective = "multi:softprob", num_class = 3, nthread = 1) X_pred <- data.matrix(iris[, -5]) @@ -212,7 +211,6 @@ x <- shapviz( collapse = list(Species = c("Speciessetosa", "Speciesversicolor", "Speciesvirginica")) ) summary(x) -} # Similarly with LightGBM if (requireNamespace("lightgbm", quietly = TRUE)) { @@ -242,7 +240,8 @@ if (requireNamespace("lightgbm", quietly = TRUE)) { all.equal(mx[[3]], x) } } +} \seealso{ -\code{\link[=sv_importance]{sv_importance()}}, \code{\link[=sv_dependence]{sv_dependence()}}, \code{\link[=sv_interaction]{sv_interaction()}}, +\code{\link[=sv_importance]{sv_importance()}}, \code{\link[=sv_dependence]{sv_dependence()}}, \code{\link[=sv_dependence2D]{sv_dependence2D()}}, \code{\link[=sv_interaction]{sv_interaction()}}, \code{\link[=sv_waterfall]{sv_waterfall()}}, \code{\link[=sv_force]{sv_force()}}, \code{\link[=collapse_shap]{collapse_shap()}} } diff --git a/man/split.shapviz.Rd b/man/split.shapviz.Rd index 55a0cb2..35227f2 100644 --- a/man/split.shapviz.Rd +++ b/man/split.shapviz.Rd @@ -20,12 +20,14 @@ A "mshapviz" object. Splits "shapviz" object along a vector \code{f} into an object of class "mshapviz". } \examples{ +\dontrun{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) sv <- shapviz(fit, X_pred = dtrain, X = iris) mx <- split(sv, f = iris$Species) sv_dependence(mx, "Petal.Length") } +} \seealso{ \code{\link[=shapviz]{shapviz()}}, \code{\link[=rbind.shapviz]{rbind.shapviz()}} } diff --git a/man/sv_dependence.Rd b/man/sv_dependence.Rd index 44487e5..b486032 100644 --- a/man/sv_dependence.Rd +++ b/man/sv_dependence.Rd @@ -86,6 +86,7 @@ to focus on pure interaction effects (multiplied by two) or on pure main effects }} \examples{ +\dontrun{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris) @@ -95,7 +96,6 @@ sv_dependence(x, "Petal.Length", color_var = NULL) sv_dependence(x, c("Species", "Petal.Length")) sv_dependence(x, "Petal.Width", color_var = c("Species", "Petal.Length")) -\dontrun{ # SHAP interaction values/main effects x2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) sv_dependence(x2, "Petal.Length", interactions = TRUE) diff --git a/man/sv_dependence2D.Rd b/man/sv_dependence2D.Rd index bc62eff..7a685ee 100644 --- a/man/sv_dependence2D.Rd +++ b/man/sv_dependence2D.Rd @@ -93,13 +93,13 @@ to focus on pure interaction effects (multiplied by two). }} \examples{ +\dontrun{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) sv <- shapviz(fit, X_pred = dtrain, X = iris) sv_dependence2D(sv, x = "Petal.Length", y = "Species") sv_dependence2D(sv, x = c("Petal.Length", "Species"), y = "Sepal.Width") -\dontrun{ # SHAP interaction values sv2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) sv_dependence2D(sv2, x = "Petal.Length", y = "Species", interactions = TRUE) diff --git a/man/sv_force.Rd b/man/sv_force.Rd index 1881cf3..3621732 100644 --- a/man/sv_force.Rd +++ b/man/sv_force.Rd @@ -96,12 +96,11 @@ baseline SHAP value. }} \examples{ +\dontrun{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) sv_force(x) - -\dontrun{ sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5) # Aggregate over all observations with Petal.Length == 1.4 diff --git a/man/sv_importance.Rd b/man/sv_importance.Rd index 402b148..596ec13 100644 --- a/man/sv_importance.Rd +++ b/man/sv_importance.Rd @@ -111,14 +111,13 @@ are sorted in decreasing order of importance. }} \examples{ +\dontrun{ X_train <- data.matrix(iris[, -1]) dtrain <- xgboost::xgb.DMatrix(X_train, label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = X_train) sv_importance(x) sv_importance(x, kind = "no") - -\dontrun{ sv_importance(x, kind = "beeswarm", show_numbers = TRUE) } diff --git a/man/sv_interaction.Rd b/man/sv_interaction.Rd index b889818..a8390fa 100644 --- a/man/sv_interaction.Rd +++ b/man/sv_interaction.Rd @@ -87,12 +87,11 @@ The features are sorted in decreasing order of usual SHAP importance. }} \examples{ +\dontrun{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE) sv_interaction(x, kind = "no") - -\dontrun{ sv_interaction(x, max_display = 2, size = 3) } } diff --git a/man/sv_waterfall.Rd b/man/sv_waterfall.Rd index 987af0a..35ac9ec 100644 --- a/man/sv_waterfall.Rd +++ b/man/sv_waterfall.Rd @@ -102,13 +102,13 @@ baseline SHAP value. }} \examples{ +\dontrun{ dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1]) fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1) x <- shapviz(fit, X_pred = dtrain, X = iris[, -1]) sv_waterfall(x) sv_waterfall(x, row_id = 123, max_display = 2, size = 9, fill_colors = 4:5) -\dontrun{ # Ordered by colnames(x), combined with max_display sv_waterfall( x[, sort(colnames(x))], order_fun = function(s) length(s):1, max_display = 3 From daf83f45b54e81d20413402a184d9897bbdcd8a2 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 9 Jun 2023 17:13:27 +0200 Subject: [PATCH 10/10] Accepted --- CRAN-SUBMISSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index cebaeb2..ab6e4fc 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.9.0 -Date: 2023-06-08 18:22:09 UTC -SHA: 32c5b1b9f2576d24d1522daf2f62df6cb41ad6a2 +Date: 2023-06-09 14:22:29 UTC +SHA: 3f6bd1f781851c169a080adb317142b133f58147