1
$\begingroup$

Is there a metric in tensorflow.keras.metrics that counts how many time the predicted output and the real output have the same signal?

For example, if the y_pred = [-0.1, 0.3, -0.22, -1] and y_val = [-1.3, 1.2, 0.5, -2], then the output should be 0.75.

I am working on a project that takes as input, along with other features, a column of real values around 0, and should predicted if the next elements of this column should be negative or positive (regardless of their absolute value). As it's only logical, I am using tanh as the activation function, but if I use as metrics accuracy or binary_accuracy, the output is always zero.

$\endgroup$
1
$\begingroup$

It is better to formulate this problem in terms of classification, not regression. For example, you can apply sign transformation on your labels (e.g. $y = numpy.sign(y)$) before training the model, then fit the model with classification loss (like binary cross-entropy), and then you can use accuracy for measuring the performance. Using accuracy with regression setup outputs zero because comparing real numbers usually outputs False (like 1.2 != 1.19).

| improve this answer | |
$\endgroup$
0
$\begingroup$

You have to transform your $ y_{pred} $ continuos values into binary. In python it looks like something like this:

y_pred_binary = [1 if value>=0 else 0 for value in y_pred]
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.