我訓練了一個隨機森林使用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.
任何想法,如果&我怎麼能得到它?
感謝。
是的,我也發現它同時也是通過深入'caret'文檔。不過謝謝你找到信息的有用方法!事實證明'varImp()'是通過脫字符的'train()'訓練的大多數模型變得重要的方法。注意未來的用戶:雖然我不是100%確定的,沒有時間檢查,但似乎有必要有'important ='雜質'(我猜'重要性='permutation''也可以工作)作爲'train()'中的參數傳遞,以便能夠使用'varImp()'。 –
另一個說明:看起來如果你用'ranger'訓練你的模型,但沒有'caret',那麼'重要性(fit)'是獲得不同重要性的正確方法。如上所述,我認爲參數'重要性=雜質'(或'排列')需要在train()中。 –
奇怪它不適合我。沒有重要的值可用...嗯 –