-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
109 lines (82 loc) · 2.45 KB
/
README.Rmd
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-figures/",
warnings = FALSE
)
```
# Autocompboost
### Use case
```{r}
devtools::load_all()
# Use adult task from OpenML:
task = tsk("oml", task_id = 7592)
# Remove rows with missings:
task$filter(which(complete.cases(task$data())))
# Train compboost learner:
set.seed(31415)
cboost = lrn("classif.compboost", predict_type = "prob", show_output = FALSE,
learning_rate = 0.1, add_deeper_interactions = TRUE, use_components = FALSE,
stop_epsylon_for_break = 0, stop_patience = 3L, df = 2,
ncores = 4L)
cboost$train(task)
```
### Information about the stages:
```{r, fig.height=2}
library(ggplot2, quietly = TRUE)
## How much risk was explained by which stage:
rstages = cboost$getRiskStages()
knitr::kable(rstages)
#rstages = rstages[-1, ]
#rstages$stage = factor(rstages$stage, levels = rstages$stage)
#ggplot(rstages, aes(x = "", y = percentage, fill = stage)) +
# geom_bar(stat = "identity") +
# theme(legend.position = "bottom") +
# coord_flip() +
# scale_y_reverse() +
# xlab("") +
# ylab("") +
# ggtitle("Explained risk per stage") +
# labs(fill = "") +
# ggsci::scale_fill_uchicago()
```
### Univariate model
#### Feature importance
```{r}
## Feature importance
cboost$model$univariate$calculateFeatureImportance()
vip = cboost$model$univariate$calculateFeatureImportance(aggregate_bl_by_feat = TRUE)
plotFeatureImportance(cboost$model$univariate)
```
#### Partial effects
```{r, fig.height=3}
# Visualize top 4 vars:
fnms = vip$feature[seq_len(4)]
ggs = lapply(fnms, function(nm) plotPEUni(cboost$model$univariate, nm))
library(patchwork)
Reduce("+", ggs)
```
### Pairwise interactions
#### Feature importance
```{r}
vip_int = cboost$model$interactions$calculateFeatureImportance()
knitr::kable(vip_int)
plotTensor(cboost$model$interactions, vip_int$baselearner[1]) + theme_minimal()
plotTensor(cboost$model$interactions, vip_int$baselearner[2]) + theme_minimal()
plotTensor(cboost$model$interactions, vip_int$baselearner[3]) + theme_minimal()
plotTensor(cboost$model$interactions, vip_int$baselearner[4]) + theme_minimal()
```
#### Prediction decomposition
```{r, fig.height=3}
library(dplyr, quietly = TRUE)
# "new observation"
newdata = task$data()[1234,]
newdata$class = NULL
knitr::kable(t(newdata))
plotIndividualContributionAC(cboost, newdata)
```