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")
Cet exercice fait partie du cours
Machine Learning with Tree-Based Models in R
Instructions
- Fit your specification to the training data using
outcomeas the target variable and all predictors to createmodel. - 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
predictionsas a column namedtrue_classand save the result aspredictions_combined. - Use the
head()function to print the first rows of the result.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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
___