本文介绍了精度指标目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Keras来构建CNN,但对于准确度"指标的确切用途却产生了误解.

I am using Keras to build a CNN and I have come to a misunderstanding about what the Accuracy metric does exactly.

我已经做过一些研究,看来它返回了模型的准确性.这些信息到底存储在哪里?这个指标会影响时代的结果吗?

I have done some research and it appears that it returns the Accuracy of the model. Where is this information stored exactly? Does this metric effect the epoch results?

我找不到任何能真正深入描述准确度"度量标准的资源.使用此指标会对我的结果有何影响?

I cannot find any resources that actually describe in depth what the Accuracy metric does. How are my results affected by using this metric?

      model.compile(
               loss="sparse_categorical_crossentropy",
               optimizer='adam',
               metrics=['accuracy']
               )

Keras文档未解释该指标的用途.

The Keras documentation does not explain the purpose of this metric.

推荐答案

在您遇到问题时,更容易检查Keras 源代码,因为任何深度学习框架的文档都很糟糕.

In case of your question it is easier to check the Keras source code, because any Deep Learning framework has a poor documentation.

首先,您需要查找如何处理字符串表示形式:

Firstly, you need to find how string representations are processed:

if metric in ('accuracy', 'acc'):
    metric_fn = metrics_module.categorical_accuracy

这紧随metric模块,其中categorical_accuracy函数为已定义:

This follows to metric module where the categorical_accuracy function is defined:

def categorical_accuracy(y_true, y_pred):
    return K.cast(K.equal(K.argmax(y_true, axis=-1),
                          K.argmax(y_pred, axis=-1)),
                  K.floatx())

很明显,该函数返回张量,并且仅在日志中显示一个数字,因此有一个包装函数,用于处理具有比较结果的张量:

It is clear that the function returns a tensor, and just a number presented in logs, so there is a wrapper function for processing the tensor with comparison results:

weighted_metric_fn = weighted_masked_objective(metric_fn)

此包装函数包含用于计算最终值的逻辑.由于未定义权重和掩码,因此仅使用简单的平均:

This wrapper function contains the logic for calculating the final values. As no weights and masks are defined, just a simple averaging is used:

return K.mean(score_array)

因此,有一个等式:

PS ,我稍微不同意 @VnC ,因为准确性和精度是不同的术语.准确度显示分类任务中正确预测的比率,精确度显示正预测值的比率(更多).

P.S. I slightly disagree with @VnC, because accuracy and precision are different terms. Accuracy shows the rate of correct predictions in a classification task, and precision shows the rate of positive predicted values (more).

这篇关于精度指标目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:20