MulaiMulai sekarang secara gratis

Try a longer tune length

Recall from the video that random forest models have a primary tuning parameter of mtry, which controls how many variables are exposed to the splitting search routine at each split. For example, suppose that a tree has a total of 10 splits and mtry = 2. This means that there are 10 samples of 2 predictors each time a split is evaluated.

Use a larger tuning grid this time, but stick to the defaults provided by the train() function. Try a tuneLength of 3, rather than 1, to explore some more potential models, and plot the resulting model using the plot function.

Latihan ini adalah bagian dari kursus

Machine Learning with caret in R

Lihat Kursus

Petunjuk latihan

  • Train a random forest model, model, using the wine dataset on the quality variable with all other variables as explanatory variables. (This will take a few seconds to run, so be patient!)
  • Use method = "ranger".
  • Change the tuneLength to 3.
  • Use 5 CV folds.
  • Print model to the console.
  • Plot the model after fitting it.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Fit random forest: model
model <- train(
  ___,
  tuneLength = 1,
  data = ___, 
  method = ___,
  trControl = trainControl(
    method = "cv", 
    number = ___, 
    verboseIter = TRUE
  )
)

# Print model to console


# Plot model
Edit dan Jalankan Kode