[Python] Determining PCELoss(weight=?) for a NN with 1 binary output class?

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have a neural network for classification with 1 binary output class. The training dataset is unbalanced. 97% for 0 or False, 3% for 1 or True.

    I'm using BCELoss for the loss function. What do I send in the BCELoss(weight= ???) argument? How do calculate it? I have tried sending a tensor of (.97, .03) but is generates an error message that there is a mismatch in the number of values being sent. Here is the error message:


    RuntimeError: The size of tensor a (16) must match the size of tensor b (2) at non-singleton dimension 0
    ​

    16 is the batchsize, 2 is for (.97, 03). I think I need to send a single value times the batchsize?

    To be clear, what do I send in the nn.BCELoss(weight = ? ) when the NN has 1 binary output class? How do I calculate it? THANK YOU!

    Thank you for reading this and offering suggestions

    Continue reading...

Compartilhe esta Página