【问题标题】:Can't run confusion matrix in R无法在 R 中运行混淆矩阵
【发布时间】:2019-03-29 06:14:12
【问题描述】:

我正在尝试在 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)

【问题讨论】:

    标签: r confusion-matrix


    【解决方案1】:

    最后一行是:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-25
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      相关资源
      最近更新 更多