Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 : Decision Trees
For Part 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.
summaryiris
set.seed # for data partition
ind sample nrowiris replace TRUE, prob c
train irisind
test irisind
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.
libraryparty # for decision tree model
libraryrpart
libraryrpartplot # for decision tree plot drawing
Student's answerTop
# Load the required libraries
libraryparty
libraryrpart
libraryrpartplot
# Set the seed for reproducibility
set.seed
# Create training and test sets
ind sample nrowiris replace TRUE, prob c
train irisind
test irisind
# Construct a decision tree with rpart
tree rpartSpecies ~ data train
# Plot the decision tree
rpart.plottree
Grade cell: cellfdScore: 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started