我应该如何解释 sparse

编程入门 行业动态 更新时间:2024-10-06 22:24:07
本文介绍了我应该如何解释 sparse_categorical_crossentropy 函数的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

作为输入 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 02:16:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1402427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:sparse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!