Misunderstanding table actual vs predicted from tree

Hi. I am having trouble understanding why the following table shows me zero Predicted Yes (present): Thank you

kyphosis is a type of deformation after surgery
age is in months, number is number of vertebrae, start is highest vertebrae operated on

library(rpart)
df <- kyphosis
set.seed(1)
mytree <- rpart(Kyphosis ~ Age + Number + Start, data = df, method="class")
predicted <- predict(mytree, type="class")
t <- data.frame(df$Kyphosis,predicted[2])
colnames(t) <- c("Actual", "Predicted")
tab <- table(t)
rownames(tab) <- c("Actual no","Actual yes")
colnames(tab) <- c("Predicted no", "Predicted yes")
summary(df$Kyphosis) # shows 64 absent, 17 present
summary(predicted) # shows 55 absent, 26 present
tab # shows all 81 Predicted no (absent), 0 Predicted yes (present)

what is the intention behind the [2] here ?

1 Like

Ah, you have answered my question. The [2] should not be there. Thank you.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.