-
Notifications
You must be signed in to change notification settings - Fork 1
/
BreakDown
34 lines (29 loc) · 936 Bytes
/
BreakDown
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
# breakdown
rm(list=ls())
## Not run:
library("breakDown")
library("randomForest")
library("ggplot2")
library(dplyr)
set.seed(1313)
head(HR_data[11,-7])
model <- randomForest(factor(left)~.,
data = HR_data,
family = "binomial",
maxnodes = 5)
predict.function <- function(model, new_observation){
predict(model, new_observation, type="prob")[,2]
}
predict.function(model, HR_data[11,-7])
explain_1 <- broken(model,
HR_data[11,-7],
data = HR_data[,-7],
predict.function = predict.function,
direction = "up")
explain_1
plot(explain_1) + ggtitle("breakDown plot (direction=down) for randomForest model")
data.frame(y=explain_1$contribution,
x=explain_1$variable) %>%
ggplot(aes(x=reorder(x,y),y=y))+
geom_bar(stat="identity",fill="#1F77B4",alpha=.8)+
coord_flip()