Aan de slagGa gratis aan de slag

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") 

Deze oefening maakt deel uit van de cursus

Machine Learning with Tree-Based Models in R

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Train your model
model <- tree_spec %>% 
  ___

# Generate predictions
predictions <- ___(model,
                   ___)

# Add the true outcomes
predictions_combined <- predictions %>% 
  ___(true_class = ___)

# Print the first lines of the result
___
Code bewerken en uitvoeren