首页 > 解决方案 > tree.cv 回归的变量重要性图

问题描述

我使用回归模型创建了一个模型tree.cv()

split.tree <- sample(1:nrow(Boston), nrow(Boston) / 2)

tree.train <- Boston[split.tree,]
tree.test <- Boston[-split.tree,]

Boston.tree <- tree(medv ~ .,
                    data = Boston.train)

summary(Boston.tree)

plot(Boston.tree)
text(Boston.tree, pretty = 0)
title(main = "Unpruned Regression Tree")

tree.cv <- cv.tree(Boston.tree)

Boston.tree.prune= prune.tree(Boston.tree, best = 5)
summary(Boston.tree.prune)

plot(Boston.tree.prune)
text(Boston.tree.prune, pretty = 0)
title(main = "Pruned Regression Tree")

Boston.prune.pred <- predict(Boston.tree.prune, tree.test)

我现在有了预测,但我正在尝试绘制模型中存在的每个变量的重要性。我尝试使用 vip 包,但它似乎不适合这种类型的回归。

vip::vip(tree.cv, num_features = 40, bar = FALSE)
## Error: Model-specific variable importance scores are currently not available for this type of model.

我找到了另一个选项,varImpPlot()但它只适合randomForest. 关于如何做到这一点的任何想法?

标签: r

解决方案


推荐阅读