I'm using the bigrf R-package to analyse a dataset with ca. 50.000 observations x 120 variables, classified into two groups.

After growing a forest of 1000 trees, I investigate the importance and relationship of the 120 features in the relation to the 2 classes using, respectively, the fastimp and interactions functions, which produce very nice results.

However, I'm now interested in investigating the problem using 3 (or more) rather than 2 classes. In this case, the Gini variable importance calculated by fastimp only relates to overall importance.

My question is: Is there a way to calculate a class-specific Gini variable importance, or some similar measure?

  • $\begingroup$ see this related thread on SO. Please let me know if you find the solution. $\endgroup$
    – Antoine
    Commented Aug 15, 2015 at 18:07

2 Answers 2


I would intentionally imbalance the labels using class weights to make 3 lists of importance.


  • downrate A to 10% of actual prevalence
  • use actual prevalence
  • downrate B to 10% of actual prevalence

Then for each of these you can rank the importance, and look at those that have big and consistent changes across these tests.

Also, unless you have done a convergence study, you are likely using waay too many trees. I also like to use Boruta to estimate variable importance. The data having ~50k rows and 120 columns isn't that big that you need to get big-centric tools working.


There are multiple way of doing so

1) visualization - you can plot the abundance/frequency of each selected feature within each group as a bar plot. I assume visually the top feature will be more abundant in one group comparing with the other groups.

2) Exhaustive way - build 3 Random Forest model on each pair of two labels. Rank the features in each combination and eventually plot the result and see if gini scores for feature x is higher on both combinations.

  • $\begingroup$ I would have appreciated to heard why my answer is downgraded. I can always update and add into answers. $\endgroup$
    – Areza
    Commented May 30, 2019 at 8:44
  • 1
    $\begingroup$ Some folks are uncharitable like that. They drive me crazy. $\endgroup$ Commented Dec 1, 2020 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.