首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ranger的变量重要性

ranger的变量重要性
EN

Stack Overflow用户
提问于 2016-05-17 23:09:25
回答 3查看 25.5K关注 0票数 19

我使用caret + ranger训练了一个随机森林。

代码语言:javascript
复制
fit <- train(
    y ~ x1 + x2
    ,data = total_set
    ,method = "ranger"
    ,trControl = trainControl(method="cv", number = 5, allowParallel = TRUE, verbose = TRUE)
    ,tuneGrid = expand.grid(mtry = c(4,5,6))
    ,importance = 'impurity'
)

现在我想看看变量的重要性。但是,这些都不起作用:

代码语言:javascript
复制
> importance(fit)
Error in UseMethod("importance") : no applicable method for 'importance' applied to an object of class "c('train', 'train.formula')"
> fit$variable.importance
NULL
> fit$importance
NULL

> fit
Random Forest 

217380 samples
    32 predictors

No pre-processing
Resampling: Cross-Validated (5 fold) 
Summary of sample sizes: 173904, 173904, 173904, 173904, 173904 
Resampling results across tuning parameters:

  mtry  RMSE        Rsquared 
  4     0.03640464  0.5378731
  5     0.03645528  0.5366478
  6     0.03651451  0.5352838

RMSE was used to select the optimal model using  the smallest value.
The final value used for the model was mtry = 4. 

你知道我如何才能得到它吗?

谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-05-17 23:53:51

varImp(fit)会帮你拿到的。

为了弄清楚这一点,我查看了names(fit),它将我带到了names(fit$modelInfo) -然后你会看到varImp是其中一个选项。

票数 15
EN

Stack Overflow用户

发布于 2017-09-19 22:37:34

对于'ranger‘包,你可以调用一个重要性

代码语言:javascript
复制
fit$variable.importance

顺便说一下,您可以使用str()查看模型的所有可用输出

代码语言:javascript
复制
str(fit)
票数 9
EN

Stack Overflow用户

发布于 2017-09-03 18:59:18

根据@fmalaussena

代码语言:javascript
复制
set.seed(123)
ctrl <- trainControl(method = 'cv', 
                     number = 10,
                     classProbs = TRUE,
                     savePredictions = TRUE,
                     verboseIter = TRUE)

rfFit <- train(Species ~ ., 
               data = iris, 
               method = "ranger",
               importance = "permutation", #***
               trControl = ctrl,
               verbose = T)

您可以将"permutation""impurity"传递给参数importance。这两个值的描述都可以在这里找到:https://alexisperrier.com/datascience/2015/08/27/feature-importance-random-forests-gini-accuracy.html

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37279964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档