Keras-categorical_accuracy和sparse_categorical_accuracy之间的区别 [英] Keras - Difference between categorical_accuracy and sparse_categorical_accuracy
问题描述
Keras中的categorical_accuracy
和sparse_categorical_accuracy
有什么区别? 有关这些指标的文档中没有任何提示,并且通过询问Google博士,我没有找到答案.要么.
What is the difference between categorical_accuracy
and sparse_categorical_accuracy
in Keras? There is no hint in the documentation for these metrics, and by asking Dr. Google, I did not find answers for that either.
可以在此处找到源代码:>
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())
def sparse_categorical_accuracy(y_true, y_pred):
return K.cast(K.equal(K.max(y_true, axis=-1),
K.cast(K.argmax(y_pred, axis=-1), K.floatx())),
K.floatx())
推荐答案
查看源
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())
def sparse_categorical_accuracy(y_true, y_pred):
return K.cast(K.equal(K.max(y_true, axis=-1),
K.cast(K.argmax(y_pred, axis=-1), K.floatx())),
K.floatx())
categorical_accuracy
检查最大真实值的 index 是否等于最大预测值的 index .
categorical_accuracy
checks to see if the index of the maximal true value is equal to the index of the maximal predicted value.
sparse_categorical_accuracy
检查最大真实值是否等于最大预测值的 index .
sparse_categorical_accuracy
checks to see if the maximal true value is equal to the index of the maximal predicted value.
根据Marcin的答案,categorical_accuracy
对应于y_true
的one-hot
编码向量.
From Marcin's answer above the categorical_accuracy
corresponds to a one-hot
encoded vector for y_true
.
这篇关于Keras-categorical_accuracy和sparse_categorical_accuracy之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!