-
Notifications
You must be signed in to change notification settings - Fork 0
/
cor_train_pimp_rf.R
76 lines (69 loc) · 2.1 KB
/
cor_train_pimp_rf.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
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
set.seed(9999)
mydd = data.frame(y=fytrain, ixtrain)
## to calulate importance p-value based on purmutation
ranger_ff <- ranger(y~.,data = mydd,
num.trees = 500, mtry = 25,
## importance = "impurity_corrected",
importance = "permutation",
## importance = "hold-out",
## importance = "impurity",
write.forest = TRUE,
probability = TRUE,
min.node.size = 5,
class.weights = NULL, splitrule = "gini", classification = TRUE,
seed = 99
)
ranger_ho <- holdoutRF(y~.,data = mydd,
num.trees = 500, mtry = 25,
## importance = "impurity_corrected",
## importance = "permutation",
## importance = "hold-out",
## importance = "impurity",
write.forest = TRUE,
probability = TRUE,
min.node.size = 5,
class.weights = NULL, splitrule = "gini", classification = TRUE,
seed = 99
)
ranger_imp <- ranger_ff$variable.importance
rtemp <- data.frame(ranger_imp = ranger_imp)
row.names(rtemp) <- names(ranger_imp)
rrtemp <- rtemp %>%
arrange(-ranger_imp) %>%
slice(1:15)
rrtemp[,1] = rrtemp[,1] / rrtemp[1,1] * 100
rrtemp %>% knitr::kable()
set.seed(9999)
im_pp = importance_pvalues(ranger_ff, method = "altmann", formula = y ~ ., data = mydd,
num.permutations = 200)
pimp = sort(im_pp[,2])[1:15]
pimp %>% knitr::kable()
pimp_vv = names(pimp)[pimp < 0.1]
set.seed(9999)
mydd = data.frame(y=fytrain, ixtrain[, pimp_vv])
set.seed(1)
pimp_rf_tune <- train(
y = fytrain, x = ixtrain[, pimp_vv],
method = "ranger",
trControl = my_tr,
tuneGrid = expand.grid(
mtry = c(2,4,6,8,10),
splitrule = "gini",
min.node.size = c(5,10,15,20)),
weights = weights,
preProc = NULL,
importance = "impurity",
num.trees = 500)
## to calulate importance p-value based on purmutation
pimp_rf <- ranger(y~.,data = mydd,
num.trees = 500, mtry = 8,
## importance = "impurity_corrected",
importance = "permutation",
## importance = "hold-out",
## importance = "impurity",
write.forest = TRUE,
probability = TRUE,
min.node.size = 5,
class.weights = NULL, splitrule = "gini", classification = TRUE,
seed = 99
)