Question: Final Exam Part 1 : Decision Trees For Part 1 of the final exam, you wil use the iris data set to construct a decision

Final Exam Part 1: Decision Trees
For Part 1 of the final exam, you wil use the iris data set to construct a decision tree. You will be using the packages party and rpart to construct your decision tree.
To begin, we will import the iris data set and create training and test sets.
summary(iris)
set.seed(55) # for data partition
ind <- sample(2, nrow(iris), replace = TRUE, prob = c(0.8,0.2))
train <- iris[ind ==1,]
test <- iris[ind ==2,]
Using the output tree construct a decision tree with the function rpart with the output Species regressed on all of the explanatory variables (use a period symbol for this .). Perform this on the entire training set.
library(party) # for decision tree model
library(rpart)
library(rpart.plot) # for decision tree plot drawing
Student's answer(Top)
# Load the required libraries
library(party)
library(rpart)
library(rpart.plot)
# Set the seed for reproducibility
set.seed(55)
# Create training and test sets
ind <- sample(2, nrow(iris), replace = TRUE, prob = c(0.8,0.2))
train <- iris[ind ==1,]
test <- iris[ind ==2,]
# Construct a decision tree with rpart
tree <- rpart(Species ~ ., data = train)
# Plot the decision tree
rpart.plot(tree)
Grade cell: cell-5393427620f5d754Score: 100.0/100.0(Top)
Hidden Tests Redacted
Congratulations! All test cases in this cell passed.
Question
After thisuse the rpart function to plot the tree.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!