Keras如何计算多类别分类问题的验证准确性和训练准确性? [英] How does Keras compute validation accuracy and training accuracy for multi-class classification problems?

查看:418
本文介绍了Keras如何计算多类别分类问题的验证准确性和训练准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Keras如何计算多类分类问题(即所使用的函数)的验证和训练精度.我将模型编译如下:

I would like to know how Keras computes the validation and training accuracies for multi-class classification problems (i.e., the function used). I set my model compile as follows:

model.compile(optimizer=Adam(lr=0.001), loss='categorical_crossentropy', metrics=['accuracy'])

但是我试图了解如何计算验证准确性和训练准确性(即显式).

But I am trying to understand how is the validation accuracy and training accuracy is computed (i.e., explicit formulae).

我知道验证和训练损失是由categorical_crossentropy决定的,但是我不确定准确度.

I know the validation and training loss are determined by the categorical_crossentropy, but I am not sure about the accuracies.

注意:这不是此帖子的重复.我的问题是寻找Keras用于计算准确性的Python函数的解释,而不是上述文章中给出的理论细节.

Note: this is NOT a duplicate of this post. My question is looking for an explanation of the Python function used by Keras to compute accuracy, not the theoretical details given in the mentioned post.

推荐答案

您可以找到指标

You can find the metrics file and their implementation in the Keras github repo. In this case following metric applies:

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()) 

这通过检查预测类别是否与真实类别相同来计算单个(y_true,y_pred)对的准确性.这样做是为了比较y_pred向量中得分最高的类别的索引和y_true向量中实际类别的索引.返回0或1.

This calculates the accuracy of a single (y_true, y_pred) pair by checking if the predicted class is the same as the true class. It does this so comparing the index of the highest scoring class in y_pred vector and the index of the actual class in the y_true vector. It returns 0 or 1.

它使用此功能通过使用传统的精度公式(定义为

It uses this function to calculate the overall accuracy of the data set, by using the conventional accuracy formula, which is defined as

(amount of correct guesses)/(total amount of guesses) 

这篇关于Keras如何计算多类别分类问题的验证准确性和训练准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆