I am new to use rpart to build CART models. I wonder if the following code is printing the predicted probabilities of each class value = 1 in predictions. And pred_class saves the predicted class (with the maximum predicted probability among three classes) for each observations.
data("iris")
iris$outcome <- ifelse(iris$Species == "setosa", 1,
ifelse(iris$Species == "versicolor", 2,
ifelse(iris$Species == "virginica", 3, NA)))
my_model <- rpart::rpart(outcome ~ ., data = iris, method = "class")
iris$predictions <- predict(my_model, newdata = iris, type = "prob")
iris$pred_class <- predict(my_model, newdata = iris, type = "class")