codecamp

TensorFlow函数:tf.metrics.precision_at_k

tf.metrics.precision_at_k函数

tf.metrics.precision_at_k(
    labels,
    predictions,
    k,
    class_id=None,
    weights=None,
    metrics_collections=None,
    updates_collections=None,
    name=None
)

定义在:tensorflow/python/ops/metrics_impl.py.

计算与稀疏labels相关的predictions精度@ k.

如果指定了class_id,我们通过仅考虑class_id在top-k的最高predictions中的批次的条目来计算精度,并计算它们当中class_id确实是正确标签的分数.如果class_id未指定,我们将计算精度,因为在批处理条目预测值最高的前k类中,平均一个类是正确的,并且可以在该条目的标签中找到.

precision_at_k创建两个局部变量,true_positive_at_<k>和false_positive_at_<k>,它们被用于计算精度@K个频率.此频率最终返回为precision_at_<k>:这是一个幂等操作,简单地将true_positive_at_<k>除以总的(true_positive_at_<k>+ false_positive_at_<k>).

为了估计数据流上的度量,该函数创建一个update_op操作来更新这些变量并返回precision_at_<k>.在内部,top_k操作计算Tensor,指示顶部k predictions.设置应用于top_k和labels,通过weights计算加权的true positives和false positives.然后update_op使用得到的值递增true_positive_at_<k>和false_positive_at_<k>.

如果weights是None,则权重默认为1,使用权重0来屏蔽值.

参数:

  • labels:具有形状[D1,... DN,num_labels]或[D1,... DN]的int64 Tensor或SparseTensor,其中后者暗示num_labels = 1;N> = 1,并且num_labels是关联预测的目标类的数量;通常,N = 1并且labels具有形状[batch_size,num_labels];[D1,... DN]必须匹配predictions.值应在[0,num_classes]范围内,其中num_classes是predictions的最后一个维度;超出此范围的值将被忽略.
  • predictions:具有形状[D1,... DN,num_classes]的浮点Tensor,其中N> = 1;通常,N = 1并且predictions具有形状[batch size, num_classes].最终维度包含每个类的logit值.[D1,... DN]必须匹配labels.
  • k:整数,k表示@k metric.
  • class_id:我们想要二进制度量的整数类ID.这应该在[0,num_classes]范围内,其中num_classes是predictions的最后一个维度.如果class_id超出此范围,则该方法返回NAN.
  • weights:Tensor,其秩为0或n-1,其中n是labels的秩.如果是后者,则必须是可广播的labels(即,所有维度必须为1或者与相应的labels维度相同).
  • metrics_collections:应添加值的集合的可选列表.
  • updates_collections:应添加更新的集合的可选列表.
  • name:新更新操作的名称,以及其他从属操作的命名空间.

返回:

  • precision:标量float64 Tensor,值为true_positives除以true_positives和false_positives的值.
  • update_op:适当增加true_positives和false_positives变量的操作,其值与precision匹配.

可能引发的异常:

  • ValueError:如果weights不是None,并且它的形状与predictions不匹配,或者如果metrics_collections或updates_collections中任意一个不是一个列表或元组.
  • RuntimeError:如果启用了急切执行.
TensorFlow函数:tf.metrics.precision
TensorFlow函数:tf.metrics.precision_at_thresholds
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }