Final answer:
To split the data into a training set and a testing set, use the 'caret' package in R. Develop a CART model and draw the classification tree using the 'rpart' package. Make predictions on the test set and calculate the accuracy of the CART model.
Step-by-step explanation:
To split the data into a training set and a testing set for building a CART model, you would use the 'caret' package in R. First, load the package and set the random seed to 93 using the 'set.seed(93)' function. Then, use the 'createDataPartition' function to split the data with a 70:30 ratio, specifying the 'Drug' column as the outcome variable. This will create two data sets, one for training and one for testing.
a. To develop a CART model and draw the classification tree, you can use the 'rpart' function from the 'rpart' package in R. Simply use the formula 'Drug ~ Age + Sex + BloodPressure + Cholesterol + Na_to_K' to specify the model and pass in the training data. The resulting tree can be visualized using the 'rpart.plot' function from the 'rpart.plot' package.
b. To make predictions on the test set, you can use the 'predict' function with the trained CART model and the testing data. Specify 'type = "class"' to get the predicted drug classification for each observation. Finally, you can create a 5x5 classification matrix using the 'table' function to compare the predictions with the actual values and calculate the accuracy by dividing the sum of the diagonal elements by the total number of observations.