9、TensorFLow 中的决策函数
来源:互联网 发布:网络彩票推广员 编辑:程序博客网 时间:2024/05/18 00:21
一、分类问题的决策函数
1、多分类(包括二分类)
2、tf.nn.softmax(logits, dim=-1, name=None)
softmax = exp(logits) / reduce_sum(exp(logits), dim)
- 神经网络最后一层经过 softmax 函数后,取得概率最大的元素的 index,即为我们预测的结果
# 神经网络的输出logits = tf.constant([3.0, 1.0, -3.0]) # 正确的标签y_ = tf.constant([1.0, 0.0, 0.0])# 神经网络的输出经过 softmax 变换得到每个类别的概率y = tf.nn.softmax(logits)>>> array([ 0.87887824, 0.11894324, 0.00217852], dtype=float32))
3、tf.nn.top_k(input, k, sorted=True, name=None)
- Finds values and indices of the k largest entries for the last dimension
- 对
softmax
函数处理过的张量,取其中最大的k
个元素的值和索引
# 神经网络的输出logits = tf.constant([3.0, 1.0, -3.0]) # 正确的标签y_ = tf.constant([1.0, 0.0, 0.0])# 神经网络的输出经过 softmax 变换得到每个类别的概率y = tf.nn.softmax(logits)>>> array([ 0.87887824, 0.11894324, 0.00217852], dtype=float32))# 取得其中最大的 2 个元素的值和索引y_top_2 = tf.nn.top_k(y, 2)>>> TopKV2(values=array([ 0.87887824, 0.11894324], dtype=float32), indices=array([0, 1], dtype=int32))y_top_2.values>>> array([ 0.87887824, 0.11894324], dtype=float32)y_top_2.indices>>> array([0, 1], dtype=int32)
4、tf.nn.in_top_k(predictions, targets, k, name=None)
- 判断
targets
(索引类标[0, 1, 2, …, n-1]) 是否在top K predictions
中,若在其中,则返回True,不在则返回 False - 返回一个
bool
类型的一维张量,shape 为 [batch_size]
二、回归问题的决策函数
回归问题的决策函数:
前向传播过程中最后一层神经网络的输出结果即为网络的预测结果
三、参考资料
1、https://www.tensorflow.org/api_docs/python/tf/nn/top_k
2、Tensorflow Python API 翻译(nn)
阅读全文
0 0
- 9、TensorFLow 中的决策函数
- tensorflow中的优化函数
- tensorflow中的激活函数
- tensorflow中的一些重要函数
- Tensorflow中的变量初始化函数
- tensorflow中的lrn函数详解
- tensorflow中的pad函数解释
- 8、TensorFlow 中的激活函数
- 10、TensorFLow 中的损失函数
- 决策和循环、函数
- 系统分析中的决策问题
- tensorflow中的tf.nn这类函数
- tensorflow中的基本函数和意思
- tensorflow中的随机裁剪函数random_crop
- 关于Tensorflow中的tf.train.batch函数
- tensorflow中的常用函数(不断更新)
- Tensorflow中的学习率递减函数
- tensorflow中的矩阵生成与变换函数
- ROM、RAM、DRAM、SRAM和FLASH的区别
- leetCode-Maximum Average Subarray I
- luogu P1563 玩具谜题(NOIP 2016TG)
- 机器学习-聚类算法
- c# 托举
- 9、TensorFLow 中的决策函数
- defer的用法研究
- windows环境下学习googletest记录
- Python爬虫(六)爬京东商品图片
- matplotlib设置轴标签
- 【珍爱生命,远离苏宁】在天猫苏宁易购旗舰店买到有问题的ipad,点进来,一起维权!维权群号:567621779
- 接收并解析ICMP报文
- 10、TensorFLow 中的损失函数
- ORA-12560: TNS: 协议适配器错误