Keras-categorical_accuracy和sparse_categorical_accuracy之间的区别 [英] Keras - Difference between categorical_accuracy and sparse_categorical_accuracy

查看:566
本文介绍了Keras-categorical_accuracy和sparse_categorical_accuracy之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Keras中的categorical_accuracysparse_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_trueone-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屋!

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