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.
This exercise is part of the course
Machine Learning with Tree-Based Models in R
Exercise instructions
- Create
tree_spec
, a specification for a decision tree with anrpart
engine. - Train a model
tree_model_bmi
, where theoutcome
depends only on thebmi
predictor by fitting thediabetes
dataset to the specification. - Print the model to the console.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the specification
tree_spec <- ___() %>%
___("rpart") %>%
___
# Train the model
tree_model_bmi <- tree_spec %>%
___
# Print the model
___