НачатьНачать бесплатно

Train a regression tree

As you know already, decision trees are a useful tool for classification problems. Moreover, you can also use them to model regression problems. The structural difference is that there will be numeric values (instead of classes) on the leaf nodes.

In this exercise, you will use the chocolate dataset to fit a regression tree. This is very similar to what you already did in Chapter 1 with the diabetes dataset.

Available in your workspace is the training data chocolate_train.

Это упражнение является частью курса

Machine Learning with Tree-Based Models in R

Посмотреть курс

Инструкции к упражнению

  • Build model_spec, a regression tree specification.
  • Using the chocolate_train data frame, use model_spec to train a regression tree that predicts final_grade using only the numerical predictors in the data.

Интерактивное практическое упражнение

Попробуйте выполнить это упражнение, дополнив этот пример кода.

library(tidymodels)

# Build the specification
model_spec <- decision_tree() %>%
  set_mode(___) %>%
  set_engine(___)

# Fit to the data
model_fit <- model_spec %>%
  ___(formula = ___,
      data = ___)

model_fit
Редактировать и запускать код