You did not provide a reproducible example, so I will create a synthetic dataset:
set.seed(144)
df = data.frame(outcome = as.factor(sample(c(0, 1), 100, replace=T)),
x = rnorm(100))
The function predictfor model rpartc type="class"will return the predicted class for each observation.
library(rpart)
mod = rpart(outcome ~ x, data=df)
pred = predict(mod, type="class")
table(pred)
Finally, you can build a matrix of confusion by running tablebetween the prediction and the true result:
table(pred, df$outcome)
source
share