Return the per-sample weight needed to make a WeightedRandomSampler draw each class with equal probability.
Signature: def balanced_weights(labels: list) -> list
Weight for sample i is 1 / count(class_of_sample_i). Return a list of floats the same length as labels.
Math
Asked at
import numpy as np
def balanced_weights(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?