Balanced Class Weights

easy
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 8. Everything before it counts as cleared.

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