wait a second.

you're not using the values in classes... I would expect the weights to match the order of the values in classes ie. weight[0] corresponds to classes[0]

can you test this by passing as input unordered classes?

try also when a class is absent from y if not tested yet