0
$\begingroup$

I have created a random forest for binary classification. I have a very unbalanced dataset (taken from the actual distribution of the data the model will predict) - tens of thousands of negative cases and only a few hundred positive ones (98% negative). Given the small size of the positive corpus, I would like to refrain as much as possible from creating a separate testing/validation data set.

I believe random forests have a built-in out-of-bag scoring metric (it is also a callable attribute of sklearn random forests). Due to this bagging, the model is already not seeing ~1/3 of the training set (if I am understanding the oob method). Can I somehow leverage this unseen portion of the training set from within sklearn to generate the needed parameters?

The sklearn.metrics functions require y_true: an array of correct labels for some arbitrary list of x's, and y_pred: an array of the labels the model actually gave those arbitrary x's. This would be fairly straightforward to obtain if you have a test set of x's. I want to use the values that were not bagged to construct my test set. How can I discover which training examples were not selected in the bagging process?

Thanks.

$\endgroup$
0
$\begingroup$

The OOB sample is different for every tree in the forest. I don't think the main reason the OOB sample exists is so that it can be used as a test set (although that is certainly a benefit of its existence) the main reason is that it is created as a byproduct of bootstrapping the data for the reason of creating variation in the trees in the forest.

If you are having issues with unbalanced data maybe you could instead try oversampling your data which would make your training set more balanced. I don't know if sklearn allows this but randomForest in R does.

Looking at the randomForest in R documentation again I don't think it oversamples per se, but it does have a classwt variable that you can set to put more reliance on minimizing the error rate for certain classes.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ +1. Thanks! I believe the sklearn parameter "class_weight" may be helpful to me. I will post back if it is. Also checking out this paper now. Will post back if I find out more, and whether sklearn is suitable for this. $\endgroup$ – H Froedge Jun 22 '18 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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