forked from cfia-data-science/PHAEDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart_category.R
26 lines (22 loc) · 1.01 KB
/
cart_category.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
# remove instances with empty category1
data_category <- data[!(data$Category1 == ""), ]
# cart model
set.seed(1)
start_time <- Sys.time()
model_cart_category <- train(Risk ~ Category1 + Category2 + Category3 + Category4,
data = data_category,
method = "rpart",
metric = "ROC",
tuneLength = 10,
trControl = trainControl(method = "cv",
number = 10,
classProbs = TRUE,
summaryFunction = twoClassSummary))
end_time <- Sys.time()
# cart running time
time_cart_category <- end_time - start_time
# cart predictions
predictions_cart_category <- predict(model_cart_category, data_category)
cm_cart_category <- confusionMatrix(predictions_cart_category, data_category$Risk)
cm_cart_category
rpart.plot(model_cart_category$finalModel)