无法在R中运行混淆矩阵

时间:2019-03-28 20:13:43

标签: r confusion-matrix

我正在尝试为我的决策树模型在R中运行混淆矩阵,但是出现以下错误:

  

“表(数据,引用,dnn = dnn,...)中的错误:所有参数的长度必须相同”

我不明白为什么它不会运行。

dtree_test <- rpart(writeoff ~ education+employ_status+residential_status+loan_amount+loan_length+
                      net_income,method="class", data=testnew,parms=list(split="information"))
dtree_test$cptable

plotcp(dtree_test)

dtree_test.pruned <- prune(dtree_test, cp=.01`enter code here`639344)
prp(dtree_test.pruned, type = 2, extra = 104,
    fallen.leaves = TRUE, main="Decision Tree")
dtree_test.pred <- predict(dtree_test.pruned, testnew, type="class")

dtree_test.perf <- table(testnew$writeoff, dtree_test.pred,
                         dnn=c("Actual", "Predicted"))
dtree_test.perf
confusionMatrix(predict(dtree_test.pruned, testnew, type="class"),train$writeoff)

1 个答案:

答案 0 :(得分:0)

最后一行是:

confusionMatrix(predict(dtree_test.pruned, testnew, type="class"),train$writeoff)

为数据集testnew进行预测,但将其与数据集train中的响应进行比较。

rpart(...)中您也有data=testnew,但也许您是想使用训练数据来拟合模型?