ComenzarEmpieza gratis

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

Este ejercicio forma parte del curso

Machine Learning with Tree-Based Models in R

Ver curso

Instrucciones del ejercicio

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

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# 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
___
Editar y ejecutar código