[英]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.