Skip to content

regarding use of loss function sklearn make_circles classification problem #1126

Answered by LuluW8071
harivan86 asked this question in Q&A
Discussion options

You must be logged in to vote

@harivan86 You were passing the rounded logit values (after applying sigmoid) to the loss function causing the loss (BCE Loss) not to decrease.

Note

Use y_pred = torch.round(torch.sigmoid(y_logits)) to calculate accuracy. For BCELoss, as stated in the PyTorch documentation, pass the sigmoid logits only rather than the rounded sigmoid logit values.
https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html

Here’s the corrected code:

for epoch in range(epochs):
    model_3.train()
    # 1. Forward pass
    y_logits = model_3(X_train).squeeze()
    y_pred = torch.sigmoid(y_logits)  # Convert logits to prediction probabilities

    # 2. Calculate loss and accuracy
    loss = loss_fn(y_pred

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@harivan86
Comment options

@LuluW8071
Comment options

Answer selected by harivan86
@harivan86
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants