Variable importance with ranger
<p>I trained a random forest using <code>caret</code> + <code>ranger</code>. </p>

<pre><code>fit &lt;- 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'
)
</code></pre>

<p>Now I'd like to see the importance of variables. However, none of these work :</p>

<pre><code>&gt; importance(fit)
Error in UseMethod("importance") : no applicable method for 'importance' applied to an object of class "c('train', 'train.formula')"
&gt; fit$variable.importance
NULL
&gt; fit$importance
NULL

&gt; 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. 
</code></pre>

<p>Any idea if &amp; how I can get it ? </p>

<p>Thanks.</p>