library(rpart)
library(rpart.plot)
set.seed(123)
load(file = "ncbirths.Rdata")
head(ncbirths)
library(rpart)
library(rpart.plot)
set.seed(123)
train_index <- sample(1:nrow(ncbirths), size = 0.7 * nrow(ncbirths))
train <- ncbirths[train_index, ]
test <- ncbirths[-train_index, ]
tree <- rpart(weight ~ ., data = train, method = "class")
rpart.plot(tree, main = "Decision Tree for the ncbirths Dataset",box.palette = "blue", shadow.col = 0)