Classification with two classes
fordanic opened this issue · 1 comments
Set up a network for classification but with only two classes, hence, I set number of nodes in the output layer to 1, which rendered me the following error when running the training:
/home/da-for/.local/lib/python2.7/site-packages/theano/tensor/subtensor.pyc in perform(self, node, inputs, out_)
2086 # TODO: in general, we need to re-pack the inputs into a valid
2087 # index, just like subtensor
-> 2088 out[0] = inputs[0].__getitem__(inputs[1:])
2089 if (numpy.__version__ <= '1.6.1' and
2090 out[0].size != numpy.uint32(out[0].size)):
IndexError: index 1 is out of bounds for axis 1 with size 1
Apply node that caused the error: AdvancedSubtensor(Reshape{2}.0, ARange.0, Reshape{1}.0)
Inputs types: [TensorType(float64, matrix), TensorType(int64, vector), TensorType(int32, vector)]
Inputs shapes: [(32, 1), (32,), (32,)]
Inputs strides: [(8, 8), (8,), (4,)]
Inputs values: ['not shown', 'not shown', 'not shown']
However, using two output nodes and everything was ok.
Not sure whether it's something that happens in theanets before reaching Theano or if simply Theano requires two output nodes when running classification with only two classes?
This happens because theanets uses a non-normalized softmax output layer for classification. The softmax must have the same number of outputs as the number of classes being considered.
In theory you can train a logistic or binary classification model using a single output node, but you'd need to write a custom loss to interpret the output node properly.