เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Variable importance

You already know that bagged trees are an ensemble model that overcomes the variance problem of decision trees. Now you learned that the random forest algorithm further improves this by using only a random subset of the features in each tree. This further decorrelates the ensemble, improving its predictive performance.

In this exercise, you will build a random forest yourself and plot the importance of the predictors using the vip package. The training data, customers_train, is pre-loaded in your workspace.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Machine Learning with Tree-Based Models in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Create spec, the specification of a random forest classification model using the "ranger" engine and "impurity" variable importance.
  • Create model by fitting the tibble customers_train to spec using still_customer as the outcome and all other columns as the predictor variables.
  • Plot the variable importance using the vip() function from the vip package (which is not pre-loaded).

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Specify a random forest
spec <- ___ %>%
	set_mode("classification") %>%
    set_engine(___, importance = ___)

# Train the forest
model <- spec %>%
    fit(___,
        ___)

# Plot the variable importance
vip::___(model)
แก้ไขและรันโค้ด