Spaces:
Sleeping
Sleeping
remove parallel
Browse files- calculate_shap.R +11 -11
calculate_shap.R
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
suppressPackageStartupMessages(library(dplyr))
|
2 |
suppressPackageStartupMessages(library(fastshap)) # for fast (approximate) Shapley values
|
3 |
suppressPackageStartupMessages(library(caret))
|
4 |
-
suppressPackageStartupMessages(library(doMC))
|
5 |
|
6 |
-
registerDoMC(cores = 10)
|
7 |
|
8 |
|
9 |
p_function_G <-
|
@@ -47,7 +47,7 @@ calculate_shap_deprecated <- function(dataset,model,nsim=10) {
|
|
47 |
pred_wrapper = p_function_G,
|
48 |
nsim = nsim,
|
49 |
newdata = trainset_G,
|
50 |
-
.parallel =
|
51 |
)
|
52 |
message(" - Calculating SHAP values for class GM")
|
53 |
shap_values_GM <-
|
@@ -57,7 +57,7 @@ calculate_shap_deprecated <- function(dataset,model,nsim=10) {
|
|
57 |
pred_wrapper = p_function_GM,
|
58 |
nsim = nsim,
|
59 |
newdata = trainset_GM,
|
60 |
-
.parallel =
|
61 |
)
|
62 |
message(" - Calculating SHAP values for class R")
|
63 |
shap_values_R <-
|
@@ -67,7 +67,7 @@ calculate_shap_deprecated <- function(dataset,model,nsim=10) {
|
|
67 |
pred_wrapper = p_function_R,
|
68 |
nsim = nsim,
|
69 |
newdata = trainset_R,
|
70 |
-
.parallel =
|
71 |
)
|
72 |
message(" - Calculating SHAP values for class W")
|
73 |
shap_values_W <-
|
@@ -77,7 +77,7 @@ calculate_shap_deprecated <- function(dataset,model,nsim=10) {
|
|
77 |
pred_wrapper = p_function_W,
|
78 |
nsim = nsim,
|
79 |
newdata = trainset_W,
|
80 |
-
.parallel =
|
81 |
# adjust = TRUE
|
82 |
)
|
83 |
|
@@ -170,7 +170,7 @@ calculate_shap <- function(dataset,model,nsim=10) {
|
|
170 |
pred_wrapper = p_function_G,
|
171 |
nsim = nsim,
|
172 |
newdata = trainset_G,
|
173 |
-
.parallel =
|
174 |
)
|
175 |
message(" - Calculating SHAP values for class GM")
|
176 |
shap_values_GM <-
|
@@ -180,7 +180,7 @@ calculate_shap <- function(dataset,model,nsim=10) {
|
|
180 |
pred_wrapper = p_function_GM,
|
181 |
nsim = nsim,
|
182 |
newdata = trainset_GM,
|
183 |
-
.parallel =
|
184 |
)
|
185 |
message(" - Calculating SHAP values for class R")
|
186 |
shap_values_R <-
|
@@ -190,7 +190,7 @@ calculate_shap <- function(dataset,model,nsim=10) {
|
|
190 |
pred_wrapper = p_function_R,
|
191 |
nsim = nsim,
|
192 |
newdata = trainset_R,
|
193 |
-
.parallel =
|
194 |
)
|
195 |
message(" - Calculating SHAP values for class W")
|
196 |
shap_values_W <-
|
@@ -200,7 +200,7 @@ calculate_shap <- function(dataset,model,nsim=10) {
|
|
200 |
pred_wrapper = p_function_W,
|
201 |
nsim = nsim,
|
202 |
newdata = trainset_W,
|
203 |
-
.parallel =
|
204 |
# adjust = TRUE
|
205 |
)
|
206 |
|
@@ -275,7 +275,7 @@ calculate_shap_class <- function(dataset, new_data, model,nsim=10,
|
|
275 |
pred_wrapper = function_class,
|
276 |
nsim = nsim,
|
277 |
newdata = new_data_class,
|
278 |
-
.parallel =
|
279 |
)
|
280 |
|
281 |
shap_values_class$class<-Activity
|
|
|
1 |
suppressPackageStartupMessages(library(dplyr))
|
2 |
suppressPackageStartupMessages(library(fastshap)) # for fast (approximate) Shapley values
|
3 |
suppressPackageStartupMessages(library(caret))
|
4 |
+
#suppressPackageStartupMessages(library(doMC))
|
5 |
|
6 |
+
#registerDoMC(cores = 10)
|
7 |
|
8 |
|
9 |
p_function_G <-
|
|
|
47 |
pred_wrapper = p_function_G,
|
48 |
nsim = nsim,
|
49 |
newdata = trainset_G,
|
50 |
+
.parallel = FALSE
|
51 |
)
|
52 |
message(" - Calculating SHAP values for class GM")
|
53 |
shap_values_GM <-
|
|
|
57 |
pred_wrapper = p_function_GM,
|
58 |
nsim = nsim,
|
59 |
newdata = trainset_GM,
|
60 |
+
.parallel = FALSE
|
61 |
)
|
62 |
message(" - Calculating SHAP values for class R")
|
63 |
shap_values_R <-
|
|
|
67 |
pred_wrapper = p_function_R,
|
68 |
nsim = nsim,
|
69 |
newdata = trainset_R,
|
70 |
+
.parallel = FALSE
|
71 |
)
|
72 |
message(" - Calculating SHAP values for class W")
|
73 |
shap_values_W <-
|
|
|
77 |
pred_wrapper = p_function_W,
|
78 |
nsim = nsim,
|
79 |
newdata = trainset_W,
|
80 |
+
.parallel = FALSE
|
81 |
# adjust = TRUE
|
82 |
)
|
83 |
|
|
|
170 |
pred_wrapper = p_function_G,
|
171 |
nsim = nsim,
|
172 |
newdata = trainset_G,
|
173 |
+
.parallel = FALSE
|
174 |
)
|
175 |
message(" - Calculating SHAP values for class GM")
|
176 |
shap_values_GM <-
|
|
|
180 |
pred_wrapper = p_function_GM,
|
181 |
nsim = nsim,
|
182 |
newdata = trainset_GM,
|
183 |
+
.parallel = FALSE
|
184 |
)
|
185 |
message(" - Calculating SHAP values for class R")
|
186 |
shap_values_R <-
|
|
|
190 |
pred_wrapper = p_function_R,
|
191 |
nsim = nsim,
|
192 |
newdata = trainset_R,
|
193 |
+
.parallel = FALSE
|
194 |
)
|
195 |
message(" - Calculating SHAP values for class W")
|
196 |
shap_values_W <-
|
|
|
200 |
pred_wrapper = p_function_W,
|
201 |
nsim = nsim,
|
202 |
newdata = trainset_W,
|
203 |
+
.parallel = FALSE
|
204 |
# adjust = TRUE
|
205 |
)
|
206 |
|
|
|
275 |
pred_wrapper = function_class,
|
276 |
nsim = nsim,
|
277 |
newdata = new_data_class,
|
278 |
+
.parallel = FALSE
|
279 |
)
|
280 |
|
281 |
shap_values_class$class<-Activity
|