# Binary classification for variable outputs

I am creating a binary classifier in Keras and here's the code

model = Sequential()


The problem though, is that I have variable targets, i.e. they lie between -1 and 1. And here is a histogram of the distibution of my targets

I know that this still, could work very well for me, and the model would probably be able to predict the variable outputs, the input data is very complex, and the model might not be able to train to predict the exact outputs. I am perfectly okay of the model cannot predict the exact values, as a long as the sign of the output [-1,1] is correct.

So I thought what if the loss function gave zero loss for a prediction that has the correct sign, but gave whatever the required binary loss is, if the output has the wrong sign, this way, during training it would give importance to the highly incorrect predictions, but as soon as the sign of the predictions are right (just what I need), it doesn't consider them anymore, hopefully giving a better result. The catch here is, that if I just trained it to predict the signs of the targets, it would give all of the inputs equal importance

So my question is, does any such loss function exist in Keras or anywhere else, or do I have to create my own loss function? If I have to create my own loss function, how do I do it?

• So you need to amplify the loss when the sign of the prediction and the ground truth label have a different sign, and decrease it if they agree. right? I am not aware of any out of the box loss functions that do this, you will have to create your own. Oct 24, 2022 at 20:28

If you really just want to guess the sign, you should just build a new target : 0 if the sign is negative 1 if the sign is positive... That would fit with your binary classification approach and the metrics you want to use.

Actually what you need is a linear regression model and not a binary classifier. You can trying to predict continuous variables using a classifier. So we need to build a regression model which predicts continuous variables in a range i.e from -1 to 1.

You can do this with some changes in your code.

model = Sequential()

Instead of accuracy as the metric, use mae or mean absolute error to monitor the model's progress.