-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecisiontree.R
43 lines (33 loc) · 1.48 KB
/
decisiontree.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
#*******************************************************************************
#*******************************************************************************
# Decision tree
cp.dectree <- 0.00002
form <- as.formula(qual~.)
control <- trainControl(method = "repeatedcv",
number = 10,
repeats = 10,
summaryFunction = twoClassSummary,
classProbs=TRUE,
sampling="up")
set.seed(seed)
dectree.caret <- train(form,
data=wine.training,
cp = cp.dectree,
method="rpart",
metric="ROC",
trControl=control)
showPrunedDecisionTree <- function(){
rpart.plot(dectree.caret$finalModel,
box.palette = viridis_pal(alpha=0.6)(8))
}
showPrunedDecisionTree()
dectree.important.vars <- dectree.caret$finalModel$variable.importance[1:3]
dectree.caret.pred <- predict(dectree.caret, wine.test)
confusionMatrix(data = dectree.caret.pred, reference = wine.test$qual)
CrossTable(x=wine.test$qual, y=dectree.caret.pred,prop.chisq = F)
conf.mat.dectree <- confusionMatrix(dectree.caret.pred,as.factor(wine.test$qual))
accuracy.dectree <- conf.mat.dectree$overall[1]
accuracy.balanced.dectree <- conf.mat.dectree$byClass[11]
sensitivity.dectree <- conf.mat.dectree$byClass[1]
specificity.dectree <- conf.mat.dectree$byClass[2]
negpredval.dectree <- conf.mat.dectree$byClass[4]