This is a very basic question on using R for classification. I'm trying to use rpart for classification task and would like to have a class label as a result, i.e. I use type="class" in predict method
predict(tree, data, type = "class")
The class labels are "0" and "1". When I try to classify a single observation I get something like this:
1
0
Levels: 0 1
As I understand this is a factor with 2 levels: 0 and 1. However, why there are 2 numbers reported and what is exactly the class assigned to this observation?
Best Answer
You didn't show a dataset to replicate. You can see from a basic illustration that class typically only returns one class per prediction. Maybe in your case, 1 is the observation index and 0 is the prediction with 2 corresponding factor levels possible {0,1}.
You can also store the result in a variable and look at the structure of that variable to confirm the specific output objects using str() function. Notice the prediction attribute values and Factor names attributes are clearly specified here.