[英]R confusion matrix error - classification tree
I am pretty new to R, so apologies in advance if this is a simple question. 我对R很陌生,因此如果这是一个简单的问题,请提前道歉。
I have made a Decision Tree classification model using the rpart package. 我已经使用rpart软件包制作了决策树分类模型。
This works fine and I have used it to predict the variable in my test data. 这工作正常,我用它来预测测试数据中的变量。 I am trying to make a confusion matrix table to compare the results but I keep getting the following error:
我正在尝试制作一个混淆矩阵表来比较结果,但是我不断收到以下错误:
Error in table(EmployeeTest$Leaver, pred) :
all arguments must have the same length
I have looked online and can't seem to find the solution. 我在网上看过,似乎找不到解决方法。
The code I am using to create the matrix is as follows: 我用来创建矩阵的代码如下:
table_mat <- table(EmployeeTest$Leaver,pred)
pred is the predicted results of the model and looks like this: pred是模型的预测结果,看起来像这样:
summary(pred)
pred
Leaver :61
Non-Leaver:91
The Employee Test table contains over 100 variables but the field I am interested in looks like: Employee Test表包含100多个变量,但我感兴趣的字段如下:
summary(EmployeeTest$Leaver)
Leaver Non-Leaver
66 86
Any help would really be appreciated as I have no idea how to fix this. 任何帮助将不胜感激,因为我不知道如何解决此问题。 I know the error suggests it is to do with length but both tables contains the same variables with the same lengths.
我知道错误提示这与长度有关,但是两个表都包含具有相同长度的相同变量。
Thanks in advance. 提前致谢。
Problem Solved: if I changed 解决的问题:如果我改变了
table_mat <- table(EmployeeTest$Leaver,pred)
to 至
table_mat <- table(EmployeeTest$Leaver,pred$pred)
it some how fixed the error, despite there only being one field in the pred table 尽管在pred表中只有一个字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.