-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in Binary Classification in NeuralNetBinaryClassifier. #502
Comments
Can you tell us what criterion you are using if not As a workaround, you could override |
Yes I use BCEWithLogitsLoss. I use BCELoss and it works. I wish you could fix that problem about BCEWithLogitsLoss. |
I cannot reproduce the error. Can you please post what kind of data you use, i.e.
of X and y? Also, the code for the module would help. |
I write a case for the error.
I change the loss into BCELoss and add sigmoid function in MyNet. It works.
|
The output of the Module needs to be 1-D: import torch.nn as nn
import numpy as np
from skorch import NeuralNetBinaryClassifier
from torch.nn.functional import relu
class MyNet(nn.Module):
def __init__(self):
super(MyNet, self).__init__()
self.linear = nn.Linear(100, 50)
self.output = nn.Linear(50, 1)
def forward(self, input):
out = input
out = self.linear(out)
out = relu(out)
out = self.output(out)
return out.squeeze(-1)
X = np.random.normal(size=(200, 100)).astype('float32')
y = np.zeros(200).astype('float32')
y[:100] = 1
net = NeuralNetBinaryClassifier(MyNet) |
Ok, thank you. |
* more fit runs because of flaky output (fixes #514) * add a classes_ attribute for things like CalibratedClassifierCV (fixes #465) * make y_proba 2-dim, which works better with certain sklearn metrics (fixes #442) * automatically squeezes output if module returns (n,1) shape (fixes #502) This could break backwards compatibility if someone relies on y_proba to be 1d.
* Several improvements to NeuralNetBinaryClassifier * more fit runs because of flaky output (fixes #514) * add a classes_ attribute for things like CalibratedClassifierCV (fixes #465) * make y_proba 2-dim, which works better with certain sklearn metrics (fixes #442) * automatically squeezes output if module returns (n,1) shape (fixes #502) This could break backwards compatibility if someone relies on y_proba to be 1d. * Address reviewer comments Check shapes more precisely * Add PR number to CHANGES * Use better hyperparameters to reduce flakyness of binary classifer * Remove obsolote line in test Co-Authored-By: ottonemo <[email protected]> * Update infer method in NeuralNetBinaryClassifier * add a docstring * correct error message when output dim > 2 * also works when more than 1 output is returned
When I use BinaryClassifer, and there is always an error
ValueError: The target data should be 1-dimensional.
.I change my target data into 1-dimensional with
array.ravel()
, it showValueError: Target size (torch.Size([128])) must be the same as input size (torch.Size([128, 1]))
.When I use set criterion=nn.BCEWithLogitsLoss, it run successfully.
I thinks there is wrong in classifier.check_data().
The text was updated successfully, but these errors were encountered: