LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Machine Learning with Tree-Based Models in R

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

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

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

# Print the model
___
Code bearbeiten und ausführen