I am pretty new to R, so apologies in advance if this is a simple question.
I have made a Decision Tree classification model using the rpart package.
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:
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.