r - 如何在决策树中找到正确分类的候选人数量?
问题描述
制作数据:
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]) 中的错误:* 数据必须包含一些与参考重叠的级别。
解决方案
推荐阅读
- python - +[AVCaptureDevice initialize] 可能在调用 fork() 时已在另一个线程中进行
- google-chrome - 如何使用 selenium 在无头 chrome 中取消设置 navigator.webdriver?
- python - BeautifulSoup 返回 ConnectionError
- python - 如何在 Keras 中有效地处理重复的共享层
- c# - 在 PHP 站点中嵌入 Razor 页面不保存 cookie - 身份不起作用
- reactjs - Redux 商店不更新
- r - 在 R 中读取 .h5 文件
- c - 无法从 .csv 文件中检索数据
- javafx - JavaFX:如何在 JavaFX 应用程序外部按下时检测 CTRL 是否关闭
- php - 漂亮的 url 通过删除 get 参数不起作用