![](/img/trans.png)
[英]confusionMatrix - Error: `data` and `reference` should be factors with the same levels
[英]ConfusionMatrix Error: `data` and `reference` should be factors with the same levels
大家好,我遇到了这样的错误,我是新手,我不知道这是什么意思。 我使用神经网络函数对泰坦尼克号数据集进行分类
有什么建议吗??
str(Prediksi)
num [1:143] 0.393 0.393 0.393 0.393 0.393 ...
字符串(测试)
num [1:143, 1:10] 1 1 1 1 1 1 1 1 1 1 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:143] "1" "3" "9" "15" ...
..$ : chr [1:10] "(Intercept)" "Survived" "Pclass" "Sexmale" ...
混淆矩阵(Prediksi,测试)
Error: `data` and `reference` should be factors with the same levels.
在confusionMatrix
函数中,两个项都需要是具有相同水平的因子。 您的Prediksi
和test
都不是一个因素。
例如,
confusionMatrix(iris$Species, iris$Species)
这将起作用str(iris$Species)
返回
Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
但是, caret::confusionMatrix
将不允许character
。
看看confusionMatrix(iris$Species, as.character(iris$Species))
,
这将返回
Error: `data` and `reference` should be factors with the same levels.
此外,使用numeric
变量将不起作用。
confusionMatrix(iris$Species, iris$Sepal.Length)
Error: `data` and `reference` should be factors with the same levels.
您提供的关于您的任务的信息不足,因此很难说如何解决您的案例,但请尝试将confusionMatrix
函数中的两个术语作为具有相同级别的因素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.