Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions