1
votes

I have a multi-class classification problem for which I am trying to use a Random Forest classifier. The target is heavily unbalanced and has the following distribution-

1    34108

4     6748

5     2458

3      132

2       37

7       11

6        6

Now, I am using the "class_weight" parameter for RandomForest classifier, and from what I understand, the weights associated with the classes are in the form of {class_label: weight}

So, is the following the correct way:

rfc = RandomForestClassifier(n_estimators = 1000, class_weight = {1:0.784, 2: 0.00085, 3: 0.003, 4: 0.155, 5: 0.0566, 6: 0.00013, 7: 0.000252})

Thanks for your help!

1
Thanks but doesn't address multiclass class weight issue - Arun

1 Answers

1
votes

If you choose class_weight = "balanced", the classes will be weighted inversely proportional to how frequently they appear in the data.

In your example, you are weighting the over-represented classes more heavily than the under-represented classes. I believe this is the opposite of what you want to achieve.

A basic formula to calculate the weight of each class is total observations / (number of classes * observations in class).