Decision trees

R
Published

October 7, 2023

library('tidyverse')
library('rpart')
library('rpart.plot')
set.seed(1)
train_index <- sample(1:nrow(iris), size = 0.7 * nrow(iris))
train <- iris[train_index, ]
test <- iris[-train_index, ]

tree <- rpart(Species ~ ., data = train, method = "class")

rpart.plot(tree, main = "Decision Tree for the Iris Dataset")

cfit2 <- rpart(pgstat ~ age + eet + g2 + grade + gleason + ploidy,
               data = stagec)

rpart.plot(cfit2, main = "Decision Tree for the stagec Dataset")