Weighted Random Sampler

WeightedRandomSampler
Can someone please explain how does WeightedRandomSampler work.
It is confusing ?
I have 5 imbalanced classes with count say [100, 20, 167, 700, 500,].
How shall I choose weights for it .
Could someone please explain it with a detailed example
@ptrblck

The WeightedRandomSampler expects weights for each sample and uses it to draw the corresponding sample. Here is an example how to use it.

1 Like

@ptrblck
Thank you but I still have one confusion
for a batch_size = 50/100
If minority class has 100 and majority class has 1000 samples respt.
Does it draw these 50/100 samples repeatedly during batch processing from minority one. I mean
Does the data loader takes the same 50/100 samples from minority class after the first batch (as there is no sample point left now) but there are still a lot sample points left now for majority class

In the default setup (replacement = True), this would be the case and the sampler would oversample the minority class, i.e. draw the same samples multiple times (and augment them if a transformation is defined in your Dataset).

1 Like

Thank you patrick
I totally got it now