Exercise

Make predictions

Making predictions with data is one of the fundamental goals of machine learning. Now that you know how to split the data and fit a model, it's time to make predictions about unseen samples with your models.

You are going to make predictions about your test set using a model obtained by fitting the training data to a tree specification.

Available in your workspace are the datasets that you generated previously (diabetes_train and diabetes_test) and a decision tree specification tree_spec, which was generated using the following code:

tree_spec <- decision_tree() %>%
  set_engine("rpart") %>%
  set_mode("classification") 

Instructions

100 XP
  • Fit your specification to the training data using outcome as the target variable and all predictors to create model.
  • Use your model to predict the outcome of diabetes for every observation in the test set and assign the result to predictions.
  • Add the true test set outcome to predictions as a column named true_class and save the result as predictions_combined.
  • Use the head() function to print the first rows of the result.