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.
The question below needs to answered
After this use the rpart function to plot he 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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 1 Lnai 9851

Authors: Paolo Frasconi ,Niels Landwehr ,Giuseppe Manco ,Jilles Vreeken

1st Edition

3319461273, 978-3319461274

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago