1
$\begingroup$

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']
)
$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – Oxbowerce
    Oct 22, 2021 at 9:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.