我一生都无法弄清楚如何在 rpart 上计算混淆矩阵。
这是我所做的:
set.seed(12345)
UBANK_rand <- UBank[order(runif(1000)), ]
UBank_train <- UBank_rand[1:900, ]
UBank_test <- UBank_rand[901:1000, ]
dim(UBank_train)
dim(UBank_test)
#Build the formula for the Decision Tree
UB_tree <- Personal.Loan ~ Experience + Age+ Income +ZIP.Code + Family + CCAvg + Education
#Building the Decision Tree from Test Data
UB_rpart <- rpart(UB_tree, data=UBank_train)
现在,我想我会做类似的事情
table(predict(UB_rpart, UBank_test, UBank_Test$Default))
但这并没有给我一个混淆矩阵。