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.
Cet exercice fait partie du cours
Machine Learning with Tree-Based Models in R
Instructions
- Create
tree_spec, a specification for a decision tree with anrpartengine. - Train a model
tree_model_bmi, where theoutcomedepends only on thebmipredictor by fitting thediabetesdataset to the specification. - Print the model to the console.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Create the specification
tree_spec <- ___() %>%
___("rpart") %>%
___
# Train the model
tree_model_bmi <- tree_spec %>%
___
# Print the model
___