How to set a class_weight Dictionary for Random Forest?

238 views Asked by At

I'm dealing with an unbalanced dataset, so I decided to use a weight dictionary for classification.

Documentation says that a weight dict must be defined as shown below: https://imbalanced-learn.org/stable/generated/imblearn.ensemble.BalancedRandomForestClassifier.html

     weight_dict = [{0: 1, 1: 1}, {0: 1, 1: 5}, {0: 1, 1: 1}, {0: 1, 1: 1}]

So, since I want to predict 12 classes which are located in the last column. I assume that the setting would be like:

weight_dict = [{0: 1, 1: 5.77390289e-01}, {0: 1, 1: 6.48317326e-01}, 
               {0: 1, 1: 1.35324885e-01}, {0: 1, 1: 2.92665797e+00}, 
               {0: 1, 1: 5.77858906e+01}, {0: 1, 1: 1.73193507e+00},
               {0: 1, 1: 9.27828244e+00}, {0: 1, 1: 1.18766082e+01}, 
               {0: 1, 1: 8.99009985e+01}, {0: 1, 1: 6.39833279e+00}, 
               {0: 1, 1: 2.55347077e+01}, {0: 1, 1: 9.47015372e+02}]

Honestly, I don't clearly understand the notation of the first indicators, I mean the:

      0:1 of {0: 1, 1: 1} 

or the:

 1: value.

Do they represent column position, label order?

What is the right way to set it?

I'll be grateful for your insights.

1

There are 1 answers

0
user1808924 On BEST ANSWER

I don't clearly understand the notation of the first indicators 0:1 of {0: 1, 1: 1}

The notation is {<class label> : <count>}. The class label is in its original (ie. untransformed) representation.

For example, the following would order the generation of an Iris training set that contains 25 samples of "setosa", and 50 samples of "versicolor" and "virginica" each:

weight_dict = {"setosa" : 25, "versicolor" : 50, "virginica" : 50}