我已经在3个班级中根据观察和预测创建了一个混淆矩阵。
classes=c("Underweight", "Normal", "Overweight")
当我计算混淆矩阵时,它按字母顺序组织表中的类。这是我的代码。
# Confusion matrix
Observations <- bmi_classification(cross.m$bmi)
Predicted <- bmi_classification(cross.m$cvpred)
conf <- table(Predicted, Observations)
library(caret)
f.conf <- confusionMatrix(conf)
print(f.conf)
这将产生以下输出:
Confusion Matrix and Statistics
Observations
Predicted Normal Overweight Underweight
Normal 17 0 1
Overweight 1 4 0
Underweight 1 0 1
所以,我希望先是超重,然后是正常,最后是超重。我试图将顺序作为一个参数传递给矩阵,但没有成功。
编辑:
我试着重新排序,
conf <- table(Predicted, Observations)
reorder = matrix(c(9, 7, 8, 3, 1, 2, 6, 4, 5), nrow=3, ncol=3)
conf.reorder <- conf[reorder]
但我得到了,
[1] 1 1 0 1 17 1 0 0 4