[英]How to Get Variable/Feature Importance From Tidymodels ranger object?
[英]Variable importance with ranger
我使用caret
+ ranger
训练了一个随机森林。
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'
)
现在我想看看变量的重要性。 但是,这些都不起作用:
> 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.
知道我是否以及如何获得它?
谢谢。
varImp(fit)
会为你得到它。
为了解决这个问题,我查看了names(fit)
,这导致了我的names(fit$modelInfo)
- 然后你会看到varImp
作为选项之一。
对于'游侠'套餐,你可以称之为重要
fit$variable.importance
作为旁注,您可以使用str()查看模型的所有可用输出
str(fit)
据@fmalaussena说
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.