Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's difference between using metrics 'acc' and tf.keras.metrics.Accuracy()

When calling a model's compile method, we can pass in metrics.

Why is tf.keras.metrics.Accuracy different than 'acc'?

For example, the following 2 calls give different results:

model.compile(optimizer=RMSprop(learning_rate=0.001),loss=tf.keras.losses.BinaryCrossentropy(),metrics=[tf.keras.metrics.Accuracy()])

vs.

model.compile(optimizer=RMSprop(learning_rate=0.001),loss=tf.keras.losses.BinaryCrossentropy(),metrics=['acc'])

I noticed that when using the callback on_epoch_end, the keys for logs dict changes for the 2 cases above. Using tf.keras.metrics.Accuracy() will result in logs with a key accuracy, but it's always 0. However, using 'acc' will result in a logs with a key acc that has values as expected.

like image 541
user3731622 Avatar asked Jan 07 '20 20:01

user3731622


People also ask

What is metrics accuracy keras?

metrics. Accuracy(name="accuracy", dtype=None) Calculates how often predictions equal labels. This metric creates two local variables, total and count that are used to compute the frequency with which y_pred matches y_true .

What is accuracy metric in Tensorflow?

The accuracy function tf. metrics. accuracy calculates how often predictions matches labels based on two local variables it creates: total and count , that are used to compute the frequency with which logits matches labels .

How is accuracy measured in Tensorflow?

Class Accuracy Defined in tensorflow/python/keras/metrics.py. Calculates how often predictions matches labels. For example, if y_true is [1, 2, 3, 4] and y_pred is [0, 2, 3, 4] then the accuracy is 3/4 or . 75.

What is metrics in Tensorflow?

A metric is a function that is used to judge the performance of your model. Metric functions are similar to loss functions, except that the results from evaluating a metric are not used when training the model. Note that you may use any loss function as a metric.

What are the accuracy metrics in keras?

Keras is a deep learning application programming interface for Python. It offers five different accuracy metrics for evaluating classifiers. This article attempts to explain these metrics at a fundamental level by exploring their components and calculations with experimentation. Logically define and calculate Accuracy — Hypothesis.

What is the difference between'ACC'and'accuracy'in keras?

Using tf.keras.metrics.Accuracy () will result in logs with a key accuracy, but it's always 0. However, using 'acc' will result in a logs with a key acc that has values as expected. Show activity on this post. tf.keras.metrics.Accuracy used class Accuracy (MeanMetricWrapper) in metrics.py.

How to monitor model performance in keras?

sometimes you want to monitor model performance by looking at charts like ROC curve or Confusion Matrix after every epoch. In Keras, metrics are passed during the compile stage as shown below. You can pass several metrics by comma separating them.

What is the difference between the accuracy metric and confusion_matrix?

The accuracy metric computes the accuracy rate across all predictions. y_true represents the true labels while y_pred represents the predicted ones. The confusion_matrix displays a table showing the true positives, true negatives, false positives, and false negatives.


1 Answers

Took some digging, but I believe the difference is:

acc used def binary_accuracy(y_true, y_pred, threshold=0.5) in metrics.py under the hood

while

tf.keras.metrics.Accuracy used class Accuracy(MeanMetricWrapper) in metrics.py.

I came to this conclusion by testing & inspecting the source code for tensorflow's keras metrics.py file

like image 86
user3731622 Avatar answered Nov 15 '22 04:11

user3731622