# About weighted BCELoss

**URL:** <https://discuss.pytorch.org/t/about-weighted-bceloss/95708>\
**Category:** Uncategorized\
**Created:** [September 9, 2020, 8:24pm UTC](https://discuss.pytorch.org/t/about-weighted-bceloss/95708 "2020-09-09T20:24:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [September 10, 2020, 8:36am UTC](https://discuss.pytorch.org/t/about-weighted-bceloss/95708/2 "2020-09-10T08:36:48Z")

</div>

1. Most likely your model is predicting the majority class only, so I guess it’s predicting the `False` class. You can check it by printing the unique predictions for the datasets.

2. You could use `nn.BCEWithLogitsLoss`, remove the `sigmoid`, and set the `pos_weight` as `number_negative_samples / number_positive_samples`. If that doesn’t work, try to use `WeightedRandomSampler` as described [here](https://discuss.pytorch.org/t/how-to-handle-imbalanced-classes/11264/2).

3. see 2.

Also, note that the accuracy can be misleading for an imbalanced dataset as described in the [Accuracy paradox](https://en.wikipedia.org/wiki/Accuracy_paradox).

---

_[View the full topic](https://discuss.pytorch.org/t/about-weighted-bceloss/95708)._
