我使用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. 你知道我如何才能得到它吗?
谢谢。
发布于 2016-05-17 23:53:51
varImp(fit)会帮你拿到的。
为了弄清楚这一点,我查看了names(fit),它将我带到了names(fit$modelInfo) -然后你会看到varImp是其中一个选项。
发布于 2017-09-19 22:37:34
对于'ranger‘包,你可以调用一个重要性
fit$variable.importance顺便说一下,您可以使用str()查看模型的所有可用输出
str(fit)发布于 2017-09-03 18:59:18
根据@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
https://stackoverflow.com/questions/37279964
复制相似问题