我有一些真实和预测的标签
truth <- factor(c("+","+","-","+","+","-","-","-","-","-"))
pred <- factor(c("+","+","-","-","+","+","-","-","+","-"))
我想建立混淆矩阵。我有一个适用于一元元素的函数
f <- function(x,y){ sum(y==pred[truth == x])}
但是,当我将它应用于外部产品以构建矩阵时,R 似乎不高兴。
outer(levels(truth), levels(truth), f)
Error in outer(levels(x), levels(x), f) :
dims [product 4] do not match the length of object [1]
R 中为此推荐的策略是什么?
我总是可以通过更高阶的东西,但这似乎很笨拙。