TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

130. Balanced Sampler Weights

Medium

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

wi​=Nci​​1​where ci​ is the class of sample i

Asked at

NumPy

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.

Upgrade to PremiumBack to problems

Already premium?