Implement balanced_weights(y) returning a dict {class: weight} with scikit-learn's "balanced" formula
for n samples and K classes, and sample_weights(y) returning a per-sample array of those weights. With balanced weights, every class contributes the same total weight.