I'm trying to predict a binary variable with both random forests and logistic regression. I've got heavily unbalanced classes (approx 1.5% of Y=1).
The default feature importance techniques in random forests are based on classification accuracy (error rate) - which has been shown to be a bad measure for unbalanced classes (see here and here).
The two standard VIMs for feature selection with RF are the Gini VIM and the permutation VIM. Roughly speaking the Gini VIM of a predictor of interest is the sum over the forest of the decreases of Gini impurity generated by this predictor whenever it was selected for splitting, scaled by the number of trees.
My question is : is that kind of method implemented in scikit-learn (like it is in the R package party
) ? Or maybe a workaround ?
PS : This question is kind of linked with an other.
scoring
is just a performance evaluation tool used in test sample, and it does not enter into the internalDecisionTreeClassifier
algo at each split node. You can only specify thecriterion
(kind of internal loss function at each split node) to be eithergini
orinformation entropy
for the tree algo.scoring
can be used in a cross-validation context where the goal is to tune some hyperparameters (likemax_depth
). In your case, you can use aGridSearchCV
to tune some of your hyperparameters using the scoring functionroc_auc
.After doing some researchs, this is what I came out with :
The output is not very sexy, but you got the idea. The weakness of this approach is that feature importance seems to be very parameters dependent. I ran it using differents params (
max_depth
,max_features
..) and I'm getting a lot different results. So I decided to run a gridsearch on parameters (scoring = 'roc_auc'
) and then apply this VIM (Variable Importance Measure) to the best model.I took my inspiration from this (great) notebook.
All suggestions/comments are most welcome !