# random forest for imbalanced data?

I have a dataset where yes=77 and no=16000, a highly imbalanced dataset. My plan was to identify the most important variables influencing the response variable using random forest and then develop a logistic regression model using the selected variable.

I am planning to use random forest package and resampling technique. I know it will reduce the type II error but increase the type I error. Is Random forest a reasonable technique for analyzing this data? Is there any other machine learning technique which would be more suitable for my case.

There are usually two methods to deal with imbalanced data while using the random forest model. One approach is cost-sensitive learning and the other is sampling. For extremely imbalanced data, random forest generally tends to be biased towards the majority class.

The cost-sensitive approach would be to assign different weights to different classes. So if the minority class is assigned a higher weight and thus higher misclassification cost, then that can help reduce its biasness towards the majority class. You can use the class weight parameter of random forest in scikit-learn to assign weights to each class.

Secondly, there are different methods of sampling such as oversampling the minority class or undersampling the majority class etc... Although simple sampling methods improve the overall model performance, its preferable to go for a more specialized sampling method such as SMOTE and others to get a better model.

Most of the machine learning models suffer from the imbalanced data problem although there are some reasons to believe that generative models generally tend to perform better in case of imbalanced datasets.

• @Mathew Drury I've seen your questions and I never answered because I don't have an answer. However, I do have one thought. If one has the/a 'correct' set of variables, then one would expect the data space to be robust in the sense that small perturbations of the data shouldn't change the class label. Of course one has no guarantee that such is the case. One might consider checking robustness using knn. If knn showed that some nhd of a given data point was largely (mostly, entirely?) the same class label, then using smote should be effective. I believe there is a (continued) – aginensky Apr 16 '18 at 16:56
• package in R that implements this. Of course this is absolutely not a theoretical explanation. I could conceive of a result that set that based on some measure of robustness as above, using smote would improve accuracy. – aginensky Apr 16 '18 at 16:58