This problem involves the OJ data set which is part of the ISLR2 package.
We first create a training set containing a random sample of 800 observations, and a test set containing the remaining observations.
set.seed(1)
train <- sample(1:nrow(OJ), 800)
OJ.train <- OJ[train, ]
OJ.test <- OJ[-train, ]
Some of the exercises are not tested by Dodona (for example the plots), but it is still useful to try them.
Fit a tree to the training data, with Purchase as the response and the other variables as predictors.
Set a seed value of 2 before running the model.
Use the summary() function to produce summary statistics about the tree, and describe the results obtained.
Store the misclassification (training) error rate in tree.misclass and the number of terminal nodes in tree.size.
(Access the necessary values in your summary object with $).
Purchase seems to be:
tree.testerror.Assume that:
ISLR2 and tree libraries have been loaded.OJ.train and OJ.test have been created.