r - Predictive model decision tree -
i want build predictive model using decision tree classification in r. used code:
library(rpart) library(caret) datayesno <- read.csv('datayesno.csv', header=t) summary(datayesno) worktrain <- sample(1:50, 40) worktest <- setdiff(1:50, worktrain) datayesno[worktrain,] datayesno[worktest,] m <- ncol(datayesno) input <- names(datayesno)[1:(m-1)] target <- “yesno” tree <- rpart(yesno~var1+var2+var3+var4+var5, data=datayesno[worktrain, c(input,target)], method="class", parms=list(split="information"), control=rpart.control(usesurrogate=0, maxsurrogate=0)) summary(tree) plot(tree) text(tree)
i got 1 root (var3
) , 2 leafs (yes
, no
). i'm not sure result. how can confusion matrix, accuracy, sensitivity, , specificity? can them caret
package?
if use model make predictions on test set, can use confusionmatrix()
measures you're looking for.
something this...
predictions <- predict(tree, worktest) cmatrix <- confusionmatrix(predictions, worktest$yesno) print(cmatrix)