Skip to content

Commit cf9b082

Browse files
committed
thread throttling
1 parent ab4c5a8 commit cf9b082

22 files changed

Lines changed: 61 additions & 41 deletions

R/plot_contribution.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#' y = target,
3636
#' objective = "reg:squarederror",
3737
#' max_depth = 3,
38-
#' nrounds = 20
38+
#' nrounds = 20,
39+
#' nthreads = 1
3940
#' )
4041
#' unified_model <- xgboost.unify(xgb_model, as.matrix(data))
4142
#' x <- head(data, 1)

R/plot_feature_dependence.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#' y = target,
3030
#' objective = "reg:squarederror",
3131
#' max_depth = 3,
32-
#' nrounds = 20
32+
#' nrounds = 20,
33+
#' nthreads = 1
3334
#' )
3435
#' unified_model <- xgboost.unify(xgb_model, as.matrix(data))
3536
#' x <- head(data, 100)

R/plot_feature_importance.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
#' y = target,
3333
#' objective = "reg:squarederror",
3434
#' max_depth = 3,
35-
#' nrounds = 20
35+
#' nrounds = 20,
36+
#' nthreads = 1
3637
#' )
3738
#' unified_model <- xgboost.unify(xgb_model, as.matrix(data))
3839
#' shaps <- treeshap(unified_model, as.matrix(head(data, 3)))

R/plot_interaction.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#' y = target,
3131
#' objective = "reg:squarederror",
3232
#' max_depth = 5,
33-
#' nrounds = 10
33+
#' nrounds = 10,
34+
#' nthreads = 1
3435
#' )
3536
#' unified_model2 <- xgboost.unify(xgb_model2, data)
3637
#' inters <- treeshap(unified_model2, as.matrix(data[1:50, ]), interactions = TRUE)

R/treeshap.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,41 @@
2828
#' library(xgboost)
2929
#' data <- fifa20$data[colnames(fifa20$data) != 'work_rate']
3030
#' target <- fifa20$target
31-
#'
31+
#'
3232
#' # calculating simple SHAP values
3333
#' xgb_model <- xgboost::xgboost(
3434
#' x = as.matrix(data),
3535
#' y = target,
3636
#' objective = "reg:squarederror",
3737
#' max_depth = 3,
38-
#' nrounds = 20
38+
#' nrounds = 20,
39+
#' nthreads = 1
3940
#' )
4041
#' unified_model <- xgboost.unify(xgb_model, as.matrix(data))
4142
#' treeshap1 <- treeshap(unified_model, head(data, 3))
4243
#' plot_contribution(treeshap1, obs = 1)
4344
#' treeshap1$shaps
44-
#'
45+
#'
4546
#' # It's possible to calcualte explanation over different part of the data set
46-
#'
47+
#'
4748
#' unified_model_rec <- set_reference_dataset(unified_model, data[1:1000, ])
4849
#' treeshap_rec <- treeshap(unified_model, head(data, 3))
4950
#' plot_contribution(treeshap_rec, obs = 1)
50-
#'
51+
#'
5152
#' # calculating SHAP interaction values
5253
#' xgb_model2 <- xgboost::xgboost(
5354
#' x = as.matrix(data),
5455
#' y = target,
5556
#' objective = "reg:squarederror",
5657
#' max_depth = 7,
57-
#' nrounds = 10
58+
#' nrounds = 10,
59+
#' nthreads = 1
5860
#' )
5961
#' unified_model2 <- xgboost.unify(xgb_model2, as.matrix(data))
6062
#' treeshap2 <- treeshap(unified_model2, head(data, 3), interactions = TRUE)
6163
#' treeshap2$interactions
6264
#' }}
63-
#'
65+
#'
6466
treeshap <- function(unified_model, x, interactions = FALSE, verbose = TRUE) {
6567
UseMethod("treeshap", unified_model)
6668
}

R/unify_gpboost.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#' \code{\link{gbm.unify}} for \code{\link[gbm:gbm]{GBM models}}
2020
#'
2121
#' \code{\link{xgboost.unify}} for \code{\link[xgboost:xgboost]{XGBoost models}}
22-
#'
22+
#'
2323
#' \code{\link{lightgbm.unify}} for \code{\link[lightgbm:lightgbm]{LightGBM models}}
2424
#'
2525
#' \code{\link{ranger.unify}} for \code{\link[ranger:ranger]{ranger models}}
@@ -40,7 +40,7 @@
4040
#' x <- gpboost::gpb.Dataset(sparse_data, label = as.matrix(data[,ncol(data)]))
4141
#' gpb_data <- gpboost::gpb.Dataset.construct(x)
4242
#' gpb_model <- gpboost::gpboost(data = gpb_data, params = param_gpb,
43-
#' verbose = -1, num_threads = 0)
43+
#' verbose = -1, num_threads = 1)
4444
#' unified_model <- gpboost.unify(gpb_model, sparse_data)
4545
#' shaps <- treeshap(unified_model, data[1:2, ])
4646
#' plot_contribution(shaps, obs = 1)
@@ -90,26 +90,26 @@ gpboost.unify <- function(gpb_model, data, recalculate = FALSE) {
9090
df <- df[, c("tree_index", "split_index", "split_feature", "Decision.type", "threshold", "Yes", "No", "Missing", "split_gain", "internal_count")]
9191
colnames(df) <- c("Tree", "Node", "Feature", "Decision.type", "Split", "Yes", "No", "Missing", "Prediction", "Cover")
9292
attr(df, "sorted") <- NULL
93-
93+
9494
ID <- paste0(df$Node, "-", df$Tree)
9595
df$Yes <- match(paste0(df$Yes, "-", df$Tree), ID)
9696
df$No <- match(paste0(df$No, "-", df$Tree), ID)
9797
df$Missing <- match(paste0(df$Missing, "-", df$Tree), ID)
98-
98+
9999
# Here we lose "Quality" information
100100
df$Prediction[!is.na(df$Feature)] <- NA
101-
101+
102102
feature_names <- jsonlite::fromJSON(gpb_model$dump_model())$feature_names
103103
data <- data[,colnames(data) %in% feature_names]
104-
104+
105105
ret <- list(model = as.data.frame(df), data = as.data.frame(data), feature_names = feature_names)
106106
class(ret) <- "model_unified"
107107
attr(ret, "missing_support") <- TRUE
108108
attr(ret, "model") <- "gpboost"
109-
109+
110110
if (recalculate) {
111111
ret <- set_reference_dataset(ret, as.data.frame(data))
112112
}
113-
113+
114114
return(ret)
115115
}

R/unify_lightgbm.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#' x <- lightgbm::lgb.Dataset(sparse_data, label = as.matrix(data[,ncol(data)]))
3838
#' lgb_data <- lightgbm::lgb.Dataset.construct(x)
3939
#' lgb_model <- lightgbm::lightgbm(data = lgb_data, params = param_lgbm,
40-
#' verbose = -1, num_threads = 0)
40+
#' verbose = -1, num_threads = 1)
4141
#' unified_model <- lightgbm.unify(lgb_model, sparse_data)
4242
#' shaps <- treeshap(unified_model, data[1:2, ])
4343
#' plot_contribution(shaps, obs = 1)

R/unify_xgboost.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#' y = target,
3232
#' objective = "reg:squarederror",
3333
#' max_depth = 3,
34-
#' nrounds = 20
34+
#' nrounds = 20,
35+
#' nthreads = 1
3536
#' )
3637
#' unified_model <- xgboost.unify(xgb_model, as.matrix(data))
3738
#' shaps <- treeshap(unified_model, data[1:2,])

cran-comments.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Resubmission
1+
# Resubmission 2
2+
3+
Resubmission after fixing warnings on too high thread count in "dont test" examples and unit tests.
4+
5+
# Resubmission 1
26

37
Resubmission after fixing a warning in a "don't" test example.
48

man/gpboost.unify.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)