1. Learn
  2. /
  3. Courses
  4. /
  5. Machine Learning with Tree-Based Models in R

Connected

Exercise

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.

Instructions

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