1

I know there is a similar Qn at Unbalanced multiclass data with XGBoost.

  1. But I don't understand the reply provided by @Esmailian. What is the actual formula to obtain 1, 0.333 and 0.167?
For example, if we have three imbalanced classes with ratios

class A = 10% class B = 30% class C = 60%

Their weights would be (dividing the smallest class by others)

class A = 1.000 class B = 0.333 class C = 0.167

  1. Will I obtain the same values with
from sklearn.utils import class_weight
classes_weights = class_weight.compute_sample_weight(
    class_weight='balanced',
    y=train_df['class']
)
Peter
  • 179
  • 2
  • 9
  • 1
    The values are calculated by dividing the percentage for the smallest class by the percentage for the specific class, so % class A / % class A, % class A / % class B, and % class A / % class A. This would give 10% / 10% = 1, 10% / 30% = 1/3, and 10% / 60% = 1/6. – Oxbowerce Oct 22 '21 at 09:10

0 Answers0