Question: 2 . This problem involves the OJ data set which is part of the ISLR package and also available on Canvas. ( a ) Create
This problem involves the OJ data set which is part of the ISLR package and also available on Canvas.
a Create a training set containing a random sample of observations, and a test set containing the remaining observations.
b Fit a tree to the training data, with Purchase as the response and the other variables as predictors. Use the summary function to produce summary statistics about the tree, and describe the results obtained. What is the training error rate? How many terminal nodes does the tree have?
c Create a plot of the tree, and interpret the results.
d Predict the response on the test data, and produce a confusion matrix comparing the test labels to the predicted test labels. What is the test error rate?
e Create a pruned tree with four terminal nodes.
f Compare the test error rates between the pruned and unpruned trees. Which is higher?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
