首页 > 解决方案 > 如何在决策树中找到正确分类的候选人数量?

问题描述

制作数据:

TrainIndex <- sample(1:929,
                     size = round(0.7*929),
                     replace = FALSE)
train_data <- elecdatacomp[TrainIndex,]
test_data <- elecdatacomp[-TrainIndex,]

建树:

tree1 <- rpart(gen_election ~ twitter + facebook + youtube, data = train_data)

我现在拥有的:

predicted_value <- predict(tree1, test_data)
pred <- factor(ifelse(predicted_value[,2] > 0.5, 1,0))
confMatTree1 <- confusionMatrix(pred, test_data$gen_election, positive = levels(test_data$gen_election)[2])

错误

混淆Matrix.default(pred, test_data$gen_election, positive = levels(test_data$gen_election)[2]) 中的错误:* 数据必须包含一些与参考重叠的级别。

标签: rdecision-treeconfusion-matrix

解决方案


推荐阅读