我应该如何解释 sparse_categorical_crossentropy 函数的输出? [英] How should I interpret the output of the sparse_categorical_crossentropy function?

查看:87
本文介绍了我应该如何解释 sparse_categorical_crossentropy 函数的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为输入 a 有一个浮点数 1.0 或 0.0.当我尝试使用我的模型和 sparse_categorical_crossentropy 损失进行预测时,我得到如下信息:[[0.4846592 0.5153408]].

As an input a have a float 1.0 or 0.0. When I try to predict with my model and the sparse_categorical_crossentropy loss I get something like: [[0.4846592 0.5153408]].

我如何知道它预测的类别是什么?

How do I know what category it predicts?

推荐答案

您看到的这些数字是给定输入样本的每个类别的概率.例如,[[0.4846592 0.5153408]] 表示给定样本属于类别 0 的概率约为 0.48,属于类别 1 的概率约为 0.51.所以你想以最高的概率参加课程,因此你可以使用 np.argmax 找出哪个索引(即 0 或 1)是最大的:

These numbers you see are the probability of each class for the given input sample. For example, [[0.4846592 0.5153408]] means that the given sample belongs to class 0 with probability of around 0.48 and it belongs to class 1 with probability of around 0.51. So you want to take the class with the highest probability and therefore you can use np.argmax to find which index (i.e. 0 or 1) is the maximum one:

import numpy as np

pred_class = np.argmax(probs, axis=-1) 

此外,这与模型的损失函数无关.这些概率由模型中的最后一层给出,很可能它使用 softmax 作为激活函数将输出归一化为概率分布.

Further, this has nothing to do with the loss function of the model. These probabilities are given by the last layer in your model which is very likely that it uses softmax as the activation function to normalize the output as a probability distribution.

这篇关于我应该如何解释 sparse_categorical_crossentropy 函数的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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