A card company's transaction table is mostly ordinary purchases with a few frauds mixed in. In When One Class Is Rare you stopped a model from ignoring the rare class with one setting, class_weight="balanced". Behind that setting is a short calculation that gives every row a weight. While the model trains, a mistake on a row costs as much as that row's weight.
The weights are chosen so that three things are true at once:
Task: write balanced_weights(labels). It takes the label of every row and returns the list of row weights, in the same order as labels, each rounded to 4 decimal places.
labels count as classes.