Skip to content

Commit d88af20

Browse files
authored
Merge pull request #96 from ModelOriented/cran_submission
Cran submission
2 parents 9e3574f + daf83f4 commit d88af20

20 files changed

+128
-151
lines changed

CRAN-SUBMISSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 0.8.0
2-
Date: 2023-05-09 17:34:27 UTC
3-
SHA: e2f9b361e5cb79eb0faa79faabceb98a4bd1726a
1+
Version: 0.9.0
2+
Date: 2023-06-09 14:22:29 UTC
3+
SHA: 3f6bd1f781851c169a080adb317142b133f58147

R/methods.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ c.shapviz <- function(...) {
271271
#' @param ... Arguments passed to `split()`.
272272
#' @returns A "mshapviz" object.
273273
#' @examples
274+
#' \dontrun{
274275
#' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1])
275-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1)
276+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
276277
#' sv <- shapviz(fit, X_pred = dtrain, X = iris)
277278
#' mx <- split(sv, f = iris$Species)
278279
#' sv_dependence(mx, "Petal.Length")
280+
#' }
279281
#' @export
280282
#' @seealso [shapviz()], [rbind.shapviz()]
281283
split.shapviz <- function(x, f, ...) {

R/shapviz.R

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#' scale of the SHAP values.
6464
#' - `S_inter`: Numeric array of SHAP interaction values (or `NULL`).
6565
#' @seealso
66-
#' [sv_importance()], [sv_dependence()], [sv_interaction()],
66+
#' [sv_importance()], [sv_dependence()], [sv_dependence2D()], [sv_interaction()],
6767
#' [sv_waterfall()], [sv_force()], [collapse_shap()]
6868
#' @examples
6969
#' S <- matrix(c(1, -1, -1, 1), ncol = 2, dimnames = list(NULL, c("x", "y")))
@@ -110,11 +110,11 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL,
110110
#' Creates a "shapviz" object from an XGBoost model.
111111
#' @export
112112
#' @examples
113-
#'
113+
#' \dontrun{
114114
#' # XGBoost models
115-
#' X_pred <- data.matrix(iris[, -1L])
116-
#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1L])
117-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50L, nthread = 1L)
115+
#' X_pred <- data.matrix(iris[, -1])
116+
#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = iris[, 1])
117+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
118118
#'
119119
#' # Will use numeric matrix "X_pred" as feature matrix
120120
#' x <- shapviz(fit, X_pred = X_pred)
@@ -129,25 +129,23 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL,
129129
#' x <- shapviz(fit, X_pred = dtrain, X = iris)
130130
#'
131131
#' # Multiclass setting
132-
#' params <- list(objective = "multi:softprob", num_class = 3L)
133-
#' X_pred <- data.matrix(iris[, -5L])
134-
#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5L]) - 1L)
135-
#' fit <- xgboost::xgb.train(
136-
#' params = params, data = dtrain, nrounds = 50L, nthread = 1L
137-
#' )
132+
#' params <- list(objective = "multi:softprob", num_class = 3, nthread = 1)
133+
#' X_pred <- data.matrix(iris[, -5])
134+
#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5]) - 1)
135+
#' fit <- xgboost::xgb.train(params = params, data = dtrain, nrounds = 10)
138136
#'
139137
#' # Select specific class
140-
#' x <- shapviz(fit, X_pred = X_pred, which_class = 3L)
138+
#' x <- shapviz(fit, X_pred = X_pred, which_class = 3)
141139
#' x
142140
#'
143141
#' # Or combine all classes to "mshapviz" object
144142
#' x <- shapviz(fit, X_pred = X_pred)
145143
#' x
146144
#'
147145
#' # What if we would have one-hot-encoded values and want to explain the original column?
148-
#' X_pred <- stats::model.matrix(~ . -1, iris[, -1L])
149-
#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 1L]))
150-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50L)
146+
#' X_pred <- stats::model.matrix(~ . -1, iris[, -1])
147+
#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 1]))
148+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
151149
#' x <- shapviz(
152150
#' fit,
153151
#' X_pred = X_pred,
@@ -159,29 +157,30 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL,
159157
#' # Similarly with LightGBM
160158
#' if (requireNamespace("lightgbm", quietly = TRUE)) {
161159
#' fit <- lightgbm::lgb.train(
162-
#' params = list(objective = "regression", num_thread = 1L),
163-
#' data = lightgbm::lgb.Dataset(X_pred, label = iris[, 1L]),
164-
#' nrounds = 50L,
165-
#' verbose = -2L
160+
#' params = list(objective = "regression", num_thread = 1),
161+
#' data = lightgbm::lgb.Dataset(X_pred, label = iris[, 1]),
162+
#' nrounds = 10,
163+
#' verbose = -2
166164
#' )
167165
#'
168166
#' x <- shapviz(fit, X_pred = X_pred)
169167
#' x
170168
#'
171169
#' # Multiclass
172-
#' params <- list(objective = "multiclass", num_class = 3L, num_thread = 1L)
173-
#' X_pred <- data.matrix(iris[, -5L])
174-
#' dtrain <- lightgbm::lgb.Dataset(X_pred, label = as.integer(iris[, 5L]) - 1L)
175-
#' fit <- lightgbm::lgb.train(params = params, data = dtrain, nrounds = 50L)
170+
#' params <- list(objective = "multiclass", num_class = 3, num_thread = 1)
171+
#' X_pred <- data.matrix(iris[, -5])
172+
#' dtrain <- lightgbm::lgb.Dataset(X_pred, label = as.integer(iris[, 5]) - 1)
173+
#' fit <- lightgbm::lgb.train(params = params, data = dtrain, nrounds = 10)
176174
#'
177175
#' # Select specific class
178-
#' x <- shapviz(fit, X_pred = X_pred, which_class = 3L)
176+
#' x <- shapviz(fit, X_pred = X_pred, which_class = 3)
179177
#' x
180178
#'
181179
#' # Or combine all classes to a "mshapviz" object
182180
#' mx <- shapviz(fit, X_pred = X_pred)
183181
#' mx
184-
#' all.equal(mx[[3L]], x)
182+
#' all.equal(mx[[3]], x)
183+
#' }
185184
#' }
186185
shapviz.xgb.Booster = function(object, X_pred, X = X_pred, which_class = NULL,
187186
collapse = NULL, interactions = FALSE, ...) {

R/sv_dependence.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,23 @@
3434
#' @param ... Arguments passed to [ggplot2::geom_jitter()].
3535
#' @returns An object of class "ggplot" (or "patchwork") representing a dependence plot.
3636
#' @examples
37+
#' \dontrun{
3738
#' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1])
38-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1)
39+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
3940
#' x <- shapviz(fit, X_pred = dtrain, X = iris)
4041
#' sv_dependence(x, "Petal.Length")
4142
#' sv_dependence(x, "Petal.Length", color_var = "Species")
4243
#' sv_dependence(x, "Petal.Length", color_var = NULL)
4344
#' sv_dependence(x, c("Species", "Petal.Length"))
4445
#' sv_dependence(x, "Petal.Width", color_var = c("Species", "Petal.Length"))
4546
#'
46-
#' # SHAP interaction values
47+
#' # SHAP interaction values/main effects
4748
#' x2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE)
4849
#' sv_dependence(x2, "Petal.Length", interactions = TRUE)
49-
#' sv_dependence(x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE)
50-
#'
51-
#' # Show main effect of "Petal.Length" for setosa and virginica separately
52-
#' mx <- c(
53-
#' setosa = x2[x2$X$Species == "setosa"],
54-
#' virginica = x2[x2$X$Species == "virginica"]
50+
#' sv_dependence(
51+
#' x2, c("Petal.Length", "Species"), color_var = NULL, interactions = TRUE
5552
#' )
56-
#' sv_dependence(mx, "Petal.Length", color_var = NULL, interactions = TRUE)
53+
#' }
5754
#' @export
5855
#' @seealso [potential_interactions()]
5956
sv_dependence <- function(object, ...) {

R/sv_dependence2D.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@
2828
#' @param ... Arguments passed to [ggplot2::geom_jitter()].
2929
#' @returns An object of class "ggplot" (or "patchwork") representing a dependence plot.
3030
#' @examples
31+
#' \dontrun{
3132
#' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1])
32-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1)
33+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
3334
#' sv <- shapviz(fit, X_pred = dtrain, X = iris)
3435
#' sv_dependence2D(sv, x = "Petal.Length", y = "Species")
35-
#' sv_dependence2D(sv, x = "Petal.Length", y = "Sepal.Width")
3636
#' sv_dependence2D(sv, x = c("Petal.Length", "Species"), y = "Sepal.Width")
37-
#' sv_dependence2D(
38-
#' sv, x = c("Petal.Length", "Species"), y = c("Petal.Width", "Sepal.Width")
39-
#' )
4037
#'
4138
#' # SHAP interaction values
4239
#' sv2 <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE)
@@ -48,6 +45,7 @@
4845
#' # mshapviz object
4946
#' mx <- split(sv, f = iris$Species)
5047
#' sv_dependence2D(mx, x = "Petal.Length", y = "Sepal.Width")
48+
#' }
5149
#' @export
5250
#' @seealso [sv_dependence()]
5351
sv_dependence2D <- function(object, ...) {

R/sv_force.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
#' (via [ggrepel::geom_text_repel()]).
1212
#' @returns An object of class "ggplot" (or "patchwork") representing a force plot.
1313
#' @examples
14+
#' \dontrun{
1415
#' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1])
15-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1)
16+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1)
1617
#' x <- shapviz(fit, X_pred = dtrain, X = iris[, -1])
1718
#' sv_force(x)
1819
#' sv_force(x, row_id = 65, max_display = 3, size = 9, fill_colors = 4:5)
1920
#'
2021
#' # Aggregate over all observations with Petal.Length == 1.4
2122
#' sv_force(x, row_id = x$X$Petal.Length == 1.4)
22-
#'
23-
#' # Combine two force plots via {patchwork}
24-
#' sv_force(c(Obs1 = x[1], Obs2 = x[2]))
23+
#' }
2524
#' @export
2625
#' @seealso [sv_waterfall()]
2726
sv_force <- function(object, ...) {

R/sv_importance.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,16 @@
4242
#' `kind = "no"` - a named numeric vector of sorted SHAP feature importances
4343
#' (or a list of such vectors in case of an object of class "mshapviz").
4444
#' @examples
45+
#' \dontrun{
4546
#' X_train <- data.matrix(iris[, -1])
4647
#' dtrain <- xgboost::xgb.DMatrix(X_train, label = iris[, 1])
47-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1)
48+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
4849
#' x <- shapviz(fit, X_pred = X_train)
4950
#' sv_importance(x)
50-
#' sv_importance(x, kind = "beeswarm", show_numbers = TRUE)
5151
#' sv_importance(x, kind = "no")
52+
#' sv_importance(x, kind = "beeswarm", show_numbers = TRUE)
53+
#' }
5254
#'
53-
#' X <- data.frame(matrix(rnorm(1000), ncol = 20))
54-
#' S <- as.matrix(X)
55-
#' x2 <- shapviz(S, X)
56-
#' sv_importance(x2)
57-
#' sv_importance(x2, max_display = 5)
5855
#' @seealso \code{\link{sv_interaction}}
5956
#' @export
6057
sv_importance <- function(object, ...) {

R/sv_interaction.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#' numeric matrix of average absolute SHAP interactions sorted by the average
1919
#' absolute SHAP values (or a list of such matrices in case of "mshapviz" object).
2020
#' @examples
21+
#' \dontrun{
2122
#' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1])
22-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1)
23+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
2324
#' x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE)
24-
#' sv_interaction(x)
25-
#' sv_interaction(x, max_display = 2, size = 3, alpha = 0.1)
2625
#' sv_interaction(x, kind = "no")
26+
#' sv_interaction(x, max_display = 2, size = 3)
27+
#' }
2728
#' @seealso [sv_importance()]
2829
#' @export
2930
sv_interaction <- function(object, ...) {

R/sv_waterfall.R

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
#' will altogether suppress adding text to the bars.
3636
#' @returns An object of class "ggplot" (or "patchwork") representing a waterfall plot.
3737
#' @examples
38+
#' \dontrun{
3839
#' dtrain <- xgboost::xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1])
39-
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 50, nthread = 1)
40+
#' fit <- xgboost::xgb.train(data = dtrain, nrounds = 20, nthread = 1)
4041
#' x <- shapviz(fit, X_pred = dtrain, X = iris[, -1])
4142
#' sv_waterfall(x)
4243
#' sv_waterfall(x, row_id = 123, max_display = 2, size = 9, fill_colors = 4:5)
@@ -48,16 +49,7 @@
4849
#'
4950
#' # Aggregate over all observations with Petal.Length == 1.4
5051
#' sv_waterfall(x, row_id = x$X$Petal.Length == 1.4)
51-
#'
52-
#' # More features
53-
#' X <- as.data.frame(matrix(1:100, nrow = 10))
54-
#' S <- as.matrix(X)
55-
#' shp <- shapviz(S, X)
56-
#' sv_waterfall(shp)
57-
#'
58-
#' # Combine two waterfall plots via {patchwork}
59-
#' sv_waterfall(c(Obs1 = x[1], Obs2 = x[2])) +
60-
#' patchwork::plot_layout(ncol = 1)
52+
#' }
6153
#' @export
6254
#' @seealso [sv_force()]
6355
sv_waterfall <- function(object, ...) {

cran-comments.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Re-resubmission
2+
3+
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.
4+
5+
# Re-resubmission
6+
7+
Examples still taking too long on Linux. No idea how to fix this except using dontruns...
8+
9+
# Resubmission
10+
11+
Examples taking too long on Linux.
12+
13+
- I have now reduced the number of examples.
14+
- And the number of boosting rounds.
15+
116
# shapviz 0.9.0
217

318
Hello CRAN team
@@ -8,29 +23,21 @@ Hello CRAN team
823

924
## Checks look good
1025

11-
### check(manual = TRUE, cran = TRUE)
12-
13-
> checking data for ASCII and uncompressed saves ... OK
14-
WARNING
15-
'qpdf' is needed for checks on size reduction of PDFs
26+
### check(manual = TRUE, cran = TRUE)
1627

1728
> checking HTML version of manual ... NOTE
1829
Skipping checking HTML validation: no command 'tidy' found
1930

20-
### check_rhub(): Some usual notes...
31+
### RHub
2132

2233
* checking package dependencies ... NOTE
2334
Packages which this enhances but not available for checking:
2435
'fastshap', 'h2o', 'lightgbm'
2536
* checking HTML version of manual ... NOTE
37+
Skipping checking HTML validation: no command 'tidy' found
2638
Skipping checking math rendering: package 'V8' unavailable
27-
* checking for non-standard things in the check directory ... NOTE
28-
Found the following files/directories:
29-
''NULL''
30-
* checking for detritus in the temp directory ... NOTE
31-
Found the following files/directories:
32-
'lastMiKTeXException'
33-
34-
### check_win_devel()
39+
40+
41+
### Winbuilder()
3542

3643
Status: OK

0 commit comments

Comments
 (0)