简体   繁体   English

如何在 R 中获得混淆矩阵?

[英]How could I obtain confusion matrix in R?

I have a table holdouTable with the column of prediction pred .我有一个带有预测pred列的表holdouTable

library(precrec)

head(holdoutTable)

enter image description here Species geometry pred 1 1 POINT (38.80153 54.88964) 0.33363164 2 1 POINT (37.83133 55.701) 0.56814105 3 1 POINT (36.48579 55.71794) 0.09608355 4 1 POINT (37.54231 55.58439) 0.10376186 5 1 POINT (37.3788 54.9587) 0.07254712 6 1 POINT (37.40738 55.00861) 0.11294458 enter image description here Species geometry pred 1 1 POINT (38.80153 54.88964) 0.33363164 2 1 POINT (37.83133 55.701) 0.56814105 3 1 POINT (36.48579 55.71794) 0.09608355 4 1 POINT (37.54231 55.58439) 0.10376186 5 1 POINT (37.3788 54.9587) 0.07254712 6 1 POINT (37.40738 55.00861) 0.11294458

I calculate ROC AUC and plot it, but I do not know how to get confusion matrix?我计算 ROC AUC 和 plot 吧,但我不知道如何得到混淆矩阵? Could anybody to help me?有人可以帮助我吗?

holdotTable$pred <- predict(mx, hddata, type = "cloglog")

precrec_hd <- evalmod(scores = holdotTable$pred, labels = holdotTable$Species)

autoplot(precrec_hd, curvetype = "ROC")

precrec_hd

Model name Dataset ID Curve type AUC 1 m1 1 ROC 0.8434492 2 m1 1 PRC 0.7676958 Model 名称 数据集 ID 曲线类型 AUC 1 m1 1 ROC 0.8434492 2 m1 1 PRC 0.7676958

PS Previously people asked me to put output of code instead screenshot of my data. PS 以前人们让我把 output 的代码而不是我的数据截图。 I am not sure that I do it successful now, because I just copy form console and paste (I putted image of holdoutTable in any case).我不确定我现在是否成功,因为我只是复制表单控制台并粘贴(无论如何我都放了holdoutTable的图像)。 If you can advise me how to put it in right way,I will be glad to know.如果您能建议我如何正确使用它,我将很高兴知道。 Thanks!谢谢!

You can do something like this:你可以这样做:

require('caret')
require('e1071')
df <- data.frame(predicted = holdotTable$pred, actual = holdotTable$Species)
#assuming pred column contains the predicted species
confusionMatrix(data = df$predicted, reference = df$actual)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM