简体   繁体   English

Keras 如何计算多类分类问题的验证准确率和训练准确率?

[英]How does Keras compute validation accuracy and training accuracy for multi-class classification problems?

I would like to know how Keras computes the validation and training accuracies for multi-class classification problems (ie, the function used).我想知道 Keras 如何计算多类分类问题的验证和训练精度(即使用的函数)。 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 (ie, explicit formulae).但我试图了解验证准确度和训练准确度是如何计算的(即,显式公式)。

I know the validation and training loss are determined by the categorical_crossentropy , but I am not sure about the accuracies.我知道验证和训练损失由categorical_crossentropy决定,但我不确定准确性。

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.我的问题是寻找对 Keras 用于计算准确性的 Python 函数的解释,而不是上述帖子中给出的理论细节。

You can find the metrics file and their implementation in the Keras github repo.您可以在 Keras github 存储库中找到指标文件及其实现。 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()) 

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.这通过检查预测类是否与真实类相同来计算单个 (y_true, y_pred) 对的准确性。 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.它这样做是为了比较 y_pred 向量中得分最高的类的索引和 y_true 向量中实际类的索引。 It returns 0 or 1.它返回 0 或 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) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何计算多类别分类的加权准确性? - How compute weighted accuracy for multi-class classification? 如何在 Keras 中显示多类图像分类任务的验证精度? - How to display validation accuracy for multi-class image classification tasks in Keras? 训练精度高,验证精度低 CNN二元分类 keras - High training accuracy, low validation accuracy CNN binary classification keras Pytorch - 计算精度 UNet 多类分割 - Pytorch - compute accuracy UNet multi-class segmentation Keras模型为多标签图像分类提供了非常低的训练和验证精度 - Keras model giving very low training and validation accuracy for multi-label image classification 验证准确性如何确定Keras二进制分类中哪个类别正确? - How does the validation accuracy decide which class is correct in a binary classification with Keras? 验证准确性低且训练准确度高-keras imagedatagenerator flow_from_directory类别分类 - Low validation accuracy with good training accuracy - keras imagedatagenerator flow_from_directory categorical classification Keras 预测精度与训练精度不匹配 - Keras prediction accuracy does not match training accuracy Keras 验证准确度为 1,但在二进制分类中仅预测 class 0? - Keras validation accuracy is 1 but only predicts only class 0 in binary classification? 如何使用 Keras 的多层感知器进行多类分类 - How to use Keras' multi layer perceptron for multi-class classification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM