Unbalanced classification using RandomForestClassifier in sklearn

前端 未结 4 1564
借酒劲吻你
借酒劲吻你 2020-12-07 15:44

I have a dataset where the classes are unbalanced. The classes are either \'1\' or \'0\' where the ratio of class \'1\':\'0\' is 5:1. How do you calculate the prediction e

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 16:30

    If the majority class is 1, and the minority class is 0, and they are in the ratio 5:1, the sample_weight array should be:

    sample_weight = np.array([5 if i == 1 else 1 for i in y])
    

    Note that you do not invert the ratios.This also applies to class_weights. The larger number is associated with the majority class.

提交回复
热议问题