I know there is a similar Qn at Unbalanced multiclass data with XGBoost.
- 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
- 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']
)
% class A / % class A
,% class A / % class B
, and% class A / % class A
. This would give10% / 10% = 1
,10% / 30% = 1/3
, and10% / 60% = 1/6
. $\endgroup$