[英]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.