-
Notifications
You must be signed in to change notification settings - Fork 0
/
Caret_ad_vs_ctrl_classification.R
97 lines (73 loc) · 3.04 KB
/
Caret_ad_vs_ctrl_classification.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Run classification analysis using 5 algorithms
library(plyr)
library(tidyverse)
library(caret)
library(Boruta)
#library(blkbox)
library(doParallel)
registerDoParallel(30)
set.seed(123)
path <- "/home/user/data"
setwd(path)
ctrl <- trainControl(method = "repeatedcv",
repeats = 20,
number = 5,
classProbs = TRUE,
savePredictions = "final",
allowParallel=TRUE,
returnData=FALSE)
tl <- 30
#tl for xgbtree shorter because it has 7 tuning parameters compared to 1-4 for others
tlx <- 10
############################################################################################
#ctrl_vs_ad
#
setwd(paste(path,"/ctrl_vs_ad", sep=""))
# labels and data files produced by the "prepare_for_m_learn" script
labels_ctrl_vs_ad = readRDS("labels_ctrl_vs_ad.rds")
data_ctrl_vs_ad = readRDS("data_ctrl_vs_ad.rds")
data_ctrl_vs_ad <- cbind(data_ctrl_vs_ad, labels_ctrl_vs_ad)
#
rf_model <- train(x = data_ctrl_vs_ad[, names(data_ctrl_vs_ad) != "labels_ctrl_vs_ad"],
y = data_ctrl_vs_ad$labels_ctrl_vs_ad,
method = "rf",
tuneLength = tl,
trControl = ctrl,
metric = "Kappa")
# save models
saveRDS(rf_model , "caret_rf_model_ctrl_vs_ad.rds")
rpart_model <- train(x = data_ctrl_vs_ad[, names(data_ctrl_vs_ad) != "labels_ctrl_vs_ad"],
y = data_ctrl_vs_ad$labels_ctrl_vs_ad,
method = "rpart",
tuneLength = tl,
trControl = ctrl,
metric = "Kappa")
# save models
saveRDS(rpart_model , "caret_rpart_model_ctrl_vs_ad.rds")
glmnet_model <- train(x = data_ctrl_vs_ad[, names(data_ctrl_vs_ad) != "labels_ctrl_vs_ad"],
y = data_ctrl_vs_ad$labels_ctrl_vs_ad,
method = "glmnet",
tuneLength = tl,
trControl = ctrl,
metric = "Kappa")
# save models
saveRDS(glmnet_model, "caret_glmnet_model_ctrl_vs_ad.rds")
ranger_model <- train(x = data_ctrl_vs_ad[, names(data_ctrl_vs_ad) != "labels_ctrl_vs_ad"],
y = data_ctrl_vs_ad$labels_ctrl_vs_ad,
method = "ranger",
tuneLength = tl,
trControl = ctrl,
metric = "Kappa")
# save models
saveRDS(ranger_model, "caret_ranger_model_ctrl_vs_ad.rds")
xgbTree_model <- train(x = data_ctrl_vs_ad[, names(data_ctrl_vs_ad) != "labels_ctrl_vs_ad"],
y = data_ctrl_vs_ad$labels_ctrl_vs_ad,
method = "xgbTree",
tuneLength = tlx,
trControl = ctrl,
metric = "Kappa",
nthread=1)
## nthread =1 necessary because xgbtree is multi-threaded by default
# save models
saveRDS(xgbTree_model, "caret_xgbtree_model_ctrl_vs_ad.rds")
############################################################################################