Hello Johnson!



 coolsuntraveler:

I think the example you gave is actually the expected behavior as described in the documentation. The mean should be divided by the number of samples, not by the sum of the weights of the expected class.


No, I think you have my example backwards.
Let’s say that you have three classes, 0, 1, 2.  Let’s say you also
have three samples, one from each class, in order.  Now suppose
that the (unweighted) per-sample loss happens to be the same for
all three samples, 1.23.
If you pass in a weight vector (class weights) of [1.0, 1.0, 3.0],
then after weighting, but before taking the “mean,” you will have a
summed, weighted loss of
1.0 * 1.23 + 1.0 * 1.23 + 3.0 * 1.23  =  5.0 * 1.23  =  6.15
If you divide by the number of samples, 3, you will get 2.05.  If you
divide by the sum of the weights, 5.0, you will get 1.23, the loss
value, that in this example, happens to be the same for each of the
three samples.
If I “average” together a bunch of numbers that all happen to have
the same value, to me it makes sense that the average should be
that value.  That’s what I meant by saying that this is my “expected
behavior” (regardless of the documentation, which I do think is
inaccurate).
Best.
K. Frank