-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiema.R
46 lines (40 loc) · 1.25 KB
/
iema.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# install.packages(c("modelStudio", "gbm", "DALEX"))
library(DALEX)
data <- fifa
data$wage_eur <- data$overall <- data$potential <- data$nationality <- NULL
data$value_eur <- log10(data$value_eur)
set.seed(1313)
library(gbm)
model <- gbm(value_eur ~ . , data = data, n.trees = 300, interaction.depth = 4)
explainer <- DALEX::explain(model,
data = data[,-1],
y = 10^data$value_eur,
predict_function = function(m,x)
10^predict(m, x, n.trees = 300),
label = 'gbm')
library(modelStudio)
# Use parallelMap to speed up the computation
options(
parallelMap.default.mode = "socket",
parallelMap.default.cpus = 4,
parallelMap.default.show.info = FALSE
)
# Pick observations
fifa_selected <- data[1:40, ]
# Make a studio for the model
iema_ms <- modelStudio(
explainer,
new_observation = fifa_selected,
B = 20,
parallel = TRUE,
rounding_function = signif, digits = 5,
options = ms_options(
#show_boxplot = FALSE,
margin_left = 160,
margin_ytitle = 100,
ms_title = "Interactive Studio for GBM model on FIFA 20 data"
)
)
iema_ms
# Save as HTML
r2d3::save_d3_html(iema_ms, file = "iema.html")