This answer by @KeremT is correct. I provide an example for those who still have problems with the exact implementation.
weight
parameter in XGBoost is per instance not per class. Therefore, we need to assign the weight of each class to its instances, which is the same thing.
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
Then, if training data is
index class
0 A
1 A
2 B
3 C
4 B
we build the weight
vector as follows:
index class weight
0 A 1.000
1 A 1.000
2 B 0.333
3 C 0.167
4 B 0.333