ComenzarEmpieza gratis

Train that model

A model specification is a good start, just like the canvas for a painter. But just as a painter needs color, the specification needs data. Only the final model is able to make predictions:

Model specification + data = model

In this exercise, you will train a decision tree that models the risk of diabetes using health variables as predictors. The response variable, outcome, indicates whether the patient has diabetes or not, which means this is a binary classification problem (there are just two classes). The dataset also contains health variables of patients like blood_pressure, age, and bmi.

For the rest of the course, the tidymodels package will always be pre-loaded. In this exercise, the diabetes dataset is also available in your workspace.

Este ejercicio forma parte del curso

Machine Learning with Tree-Based Models in R

Ver curso

Instrucciones del ejercicio

  • Create tree_spec, a specification for a decision tree with an rpart engine.
  • Train a model tree_model_bmi, where the outcome depends only on the bmi predictor by fitting the diabetes dataset to the specification.
  • Print the model to the console.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Create the specification
tree_spec <- ___() %>% 
  ___("rpart") %>% 
  ___

# Train the model
tree_model_bmi <- tree_spec %>% 
  ___

# Print the model
___
Editar y ejecutar código