tf.metrics.accuracy用于计算模型输出的准确率

tf.metrics.accuracy(labels,predictions,weights=None,metrics_collections=None,updates_collections=None,name=None
)return accuracy, update_op

参数:
labels 标签的真实值
predictions 标签的预测值
weights 每个值的权重
metrics_collections accuracy的集合
updates_collections update_op的集合

输出:
accuracy 上一个batch的准确率
update_op 加上本次训练数据后的准确率

例子:

import numpy as np
import pandas as pd
import tensorflow as tf x = tf.placeholder(tf.float64, [5])
y = tf.placeholder(tf.int32, [5])
acc, acc_op = tf.metrics.accuracy(labels=y, predictions=tf.greater_equal(x,0.5))sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
v = sess.run([acc, acc_op], feed_dict={x: [0.1, 0.5, 0.4, 0.2, 0.6], y: [1, 0, 0, 0, 1]}) #3/5
print(v)v = sess.run([acc, acc_op], feed_dict={x: [0.1, 0.6, 0.6, 0.6, 0.3], y: [1, 0, 0, 0, 1]}) #3/10
print(v)v = sess.run([acc, acc_op], feed_dict={x: [0.1, 0.6, 0.6, 0.6, 0.3], y: [1, 0, 0, 0, 1]}) #3/15
print(v)v = sess.run([acc, acc_op], feed_dict={x: [0.1, 0.6, 0.6, 0.6, 0.3], y: [1, 0, 0, 0, 1]}) #3/20
print(v)sess.close()'''
[0.0, 0.6]
[0.6, 0.3]
[0.3, 0.2]
[0.2, 0.15]
'''

如果有weights,分母为所有weights之和,分子为正确标签的weights之和

x = tf.placeholder(tf.float64, [5])
y = tf.placeholder(tf.int32, [5])
z = tf.placeholder(tf.float64, [5])
acc, acc_op = tf.metrics.accuracy(labels=y, predictions=tf.greater_equal(x,0.5), weights = z)sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
v = sess.run([acc, acc_op], feed_dict={x:[0.1, 0.1, 0.1, 0.1, 0.1], y:[0, 0, 0, 0, 0], z:[1., 1., 1., 1., 0.]}) #4/4
print(v)v = sess.run([acc, acc_op], feed_dict={x:[0.1, 0.1, 0.1, 0.1, 0.6], y:[0, 0, 0, 0, 0], z:[1., 1., 1., 1., 3.]}) #8/11
print(v)sess.close()'''
[0.0, 1.0]
[1.0, 0.72727275]
'''

tensorflow笔记 tf.metrics.accuracy相关推荐

  1. tf.metrics.accuracy

    这是tensorflow版本问题,在tensorflow2.x中,已经使用tf.compat.v1.metrics.accuracy替代tf.metrics.accuracy

  2. tensorflow笔记 tf.Print()

    调试程序的时候,经常会需要检查中间的参数,这些参数一般是定义在model或是别的函数中的局部参数,由于tensorflow要求先构建计算图再运算的机制,也不能定义后直接print出来.tensorfl ...

  3. tensorflow 里metrics_深入理解TensorFlow中的tf.metrics算子

    [IT168 技术]01 概述 本文将深入介绍Tensorflow内置的评估指标算子,以避免出现令人头疼的问题. tf.metrics.accuracy() tf.metrics.precision( ...

  4. tensorflow笔记(二十)——estimator.evaluate源码走读

    1.estimator评估流程 (1)定义model_fn 在estimator中,不论是训练.评估还是预测,都需要定义model_fn,model_fn返回EstimatorSpec对象,通常不同的 ...

  5. tf.keras.metrics.Accuracy;tf.keras.metrics.Precision;tf.keras.metrics.Recall

    tf.keras.metrics.Accuracy:tf.keras.metrics.Precision:tf.keras.metrics.Recall 当标签为0/1,而prediction为(0, ...

  6. tensorflow笔记:tf.argmax()和tf.equal()的使用

    原文:https://blog.csdn.net/abc13526222160/article/details/85299901 1.tf.argmax(vector, 1) 返回的是vector中的 ...

  7. 『tensorflow笔记』tf.argmax()和tf.equal()的使用

    1.tf.argmax(vector, 1) 返回的是vector中的最大值的索引号,如果vector是一个向量,那就返回一个值,如果是一个矩阵,那就返回一个向量,这个向量的每一个维度都是相对应矩阵行 ...

  8. tensorflow 学习笔记-- tf.reduce_max、tf.sequence_mask

    1.tf.reduce_max函数的作用:计算张量的各个维度上的元素的最大值.例子: import tensorflow as tf max_value = tf.reduce_max([1, 3, ...

  9. tensorflow 笔记 16:tf.pad

    函数: tf.compat.v1.pad tf.pad 函数表达式如下: tf.pad( tensor, paddings, mode='CONSTANT', name=None, constant_ ...

最新文章

  1. NGINX(一)内存结构
  2. tbox新增stackless协程支持
  3. DL之GRU:GRU算法相关论文、建立过程(基于TF)、相关思路配图集合、TF代码实现
  4. POJ3522Slim Span(最大边与最小边差值最小的生成树)
  5. 201506251117_《react——所需知识、主要技术》
  6. 线性表的链式存储结构(C语言版)
  7. NSLog中格式符列表
  8. layui option 动态添加_layui select动态添加option的实例
  9. python编程基础张勇答案_Python程序开发、编程基础阶段试题及答案
  10. Spark源码分析之Master资源调度算法原理
  11. PE学习.动手写PE.见缝插针
  12. awstats的简单配置
  13. RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal
  14. 任泽平:中国自动驾驶发展报告2020(上)
  15. Linux网络编程必学的TCP/IP协议——图解分层(通俗易懂)【建议新手收藏】
  16. 数据结构视频教程 -《[中山大学]算法与数据结构(C语言版)[胡青主讲]》
  17. 电机控制基础之坐标变换(Clark变换及反变换 + Park变换及反变换 + 推导 + 仿真)
  18. Oracle锁表查询和解锁方法
  19. 【阅读分享】红楼梦第一回-甄士隐的故事
  20. 格林公式求圆并的面积及重心

热门文章

  1. 电脑数据迁移高招,怎么把旧电脑的数据迁移到新电脑
  2. 【Hack The Box】linux练习-- Blunder
  3. 手机访问站点服务器劫持,手机浏览器广告泛滥?你可能被劫持了!
  4. 那些年用过的机械键盘#入坑keychron#
  5. 计算机的假桌面,如何删除桌面假Internet Explorer图标
  6. 英文记忆之拆分联想法
  7. Python案例篇3-pip install 失败 Command “python setup.py egg_info“ failed with error code 1
  8. APM32F103 RTC内部时钟源报警中断例程测试
  9. 沐风:立刻改变你的现状
  10. 计算机系统的存储器系统的任务是,第2章 计算机系统的组成.ppt