Balanced Class Weights

easy
Unit 7 · Interpretability I0/5 to milestone

Implement balanced_weights(y) returning a dict {class: weight} with scikit-learn's "balanced" formula

wc=nK⋅ncw_c = \frac{n}{K \cdot n_c}

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.

#imbalance#preprocessing2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Balanced Class Weights · TechGradify