-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_model_revisit_triage.R
50 lines (39 loc) · 1.3 KB
/
build_model_revisit_triage.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
#Pipeline for XGBoost model tuning (ED revisit - 9 days, triage)
setwd('~/ED_Return/')
library(readr)
library(plyr)
library(dplyr)
library(reshape2)
library(parallel)
library(caret)
library(xgboost)
library(doMC)
library(pROC)
registerDoMC(5) #for parallelization
load('./Results/indeces_revisit.RData')
load('./Results/sparseMatrix_revisit.RData')
x <- dataset$x[,-c(1060:1586)] #excludes variables from current ED visit
y <- dataset$y
rm(dataset)
#prepare matrices for XGBoost
x_train <- x[indeces$i_train,]
y_train <- y[indeces$i_train]
x_dev <- x[indeces$i_dev,]
y_dev <- y[indeces$i_dev]
rm(x); rm(y)
for (depth in c(15,20,25)) {
bst <- xgboost(data = x_train, label = y_train,
max_depth = depth, eta = 0.3,
nthread = 5, nrounds = 20,
eval_metric = 'auc',
objective = "binary:logistic",
colsample_bylevel = 0.03)
print(bst)
# save(bst, file = './Results/bst_model.RData')
auc_train <- as.numeric(bst$evaluation_log$train_auc[length(bst$evaluation_log$train_auc)])
#7) Predict on dev
y_hat_dev <- predict(bst, x_dev)
auc_dev <- as.numeric(auc(y_dev, y_hat_dev))
print('9day return AUC')
print(c(auc_train,auc_dev))
}