Code Monkey home page Code Monkey logo

Comments (6)

thogaertner avatar thogaertner commented on August 16, 2024 1

Solved the issue:

I set my data set to a categorical class mode with to classes, so the values were one hot encoded. Applying K.argmax() y and y_pred is solving the issue.

from concise.

Avsecz avatar Avsecz commented on August 16, 2024

The problem with Keras metrics is that they are computed for each batch and averaged on the fly. Consider a metric computed as A/B. If the denominator B is the same for all the batches (which is the case for accuracy), then the average across batches is the same as the metric computed across the whole dataset. Hower, if B varies across batches, then the average of batch metrics is not the same as the global metric.

Can you compute your metrics using

from concise.eval_metrics import *
y_pred = model.predict(x)
tpr(y_true, y_pred)
....
fpr(y_true, y_pred)

and print those together with the metrics you obtain from fig_generator?

from concise.

thogaertner avatar thogaertner commented on August 16, 2024

Thanks a lot for the fast reply.

"The problem with Keras metrics is that they are computed for each batch and averaged on the fly. Consider a metric computed as A/B. If the denominator B is the same for all the batches (which is the case for accuracy), then the average across batches is the same as the metric computed across the whole dataset. Hower, if B varies across batches, then the average of batch metrics is not the same as the global metric." - total agree. But my goal is to have a metrics with the contingency table.

I could not compute the metrics in model.compile() using the code from concise.eval_metrics.

from concise.

Avsecz avatar Avsecz commented on August 16, 2024

For model.compile you should use the metrics from concise.metrics and for the evaluation of the prediction you should use metrics from concise.eval_metrics. The reason is that the former have to be implemented with Keras functions.

from concise.

thogaertner avatar thogaertner commented on August 16, 2024

Thanks a lot. I used these functions in 'model.compile'. But the issue is, that the tpr and tnr are similar as you can see below. For testing I used just a small data set, but the values should distinguish more.

Epoch 1/3
62/62 [==============================] - 108s 2s/step - loss: 0.7520 - binary_accuracy: 0.6280 - tpr: 0.6280 - tnr: 0.6280 - val_loss: 2.5995 - val_binary_accuracy: 0.4271 - val_tpr: 0.4271 - val_tnr: 0.4271
Epoch 2/3
62/62 [==============================] - 28s 459ms/step - loss: 0.6160 - binary_accuracy: 0.6845 - tpr: 0.6845 - tnr: 0.6845 - val_loss: 0.9102 - val_binary_accuracy: 0.4870 - val_tpr: 0.4870 - val_tnr: 0.4870
Epoch 3/3
62/62 [==============================] - 27s 439ms/step - loss: 0.5802 - binary_accuracy: 0.7016 - tpr: 0.7016 - tnr: 0.7016 - val_loss: 1.6536 - val_binary_accuracy: 0.4818 - val_tpr: 0.4818 - val_tnr: 0.4818

from concise.

Kuselokusi avatar Kuselokusi commented on August 16, 2024

Good-day, Hope you are well, @tommysft I would like to ask how you accessed the tpr and tnr in the model.compile() line of code. I also have a binary classification problem, however I am having a hard time getting the tpr and tnr.

I used the code model.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ["accuracy", "tpr", "tnr"])

Please indicate what I am doing wrong.

from concise.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.