TensorFlow函數:tf.metrics.precision_at_thresholds

2018-10-13 13:42 更新

tf.metrics.precision_at_thresholds函數

tf.metrics.precision_at_thresholds(
    labels,
    predictions,
    thresholds,
    weights=None,
    metrics_collections=None,
    updates_collections=None,
    name=None
)

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

計算predictions中不同thresholds的精度值.

該precision_at_thresholds函數為閾值的不同值創(chuàng)建了四個局部變量:true_positives,true_negatives,false_positives和false_negatives.precision[i]被定義為thresholds[i]上predictions的值的總權重,其中在labels中相應的條目是True,除以thresholds[i]上的值的總權重,即,true_positives[i] / (true_positives[i] + false_positives[i]).

為了估計數據流上的度量,該函數創(chuàng)建一個update_op操作來更新這些變量并返回precision.

如果weights是None,則權重默認為1,使用權重0來屏蔽值.

參數:

  • labels:正確標記(ground truth),Tensor的維度必須與predictions匹配,將被轉換為 bool.
  • predictions:具有任意形狀的浮點Tensor,其值在范圍[0, 1]內.
  • thresholds:一個python列表或在[0, 1]范圍內浮動閾值的元組.
  • weights:可選的Tensor,其秩為0或與labels具有相同的秩,并且必須可廣播到labels(即,所有維度必須為1或者與相應的labels維度相同).
  • metrics_collections:auc應添加到的集合的可選列表.
  • updates_collections:update_op應添加到的集合的可選列表.
  • name:可選的variable_scope名稱.

返回:

  • precision:一個形狀為[len(thresholds)]的浮點Tensor.
  • update_op:表示遞增true_positives,true_negatives,false_positives和false_negatives變量的操作,它們在precision計算中使用.

可能引發(fā)的異常:

  • ValueError:如果predictions和labels有不匹配的形狀,或者weights不是None,并且它的形狀與predictions不匹配,或者如果metrics_collections或updates_collections中任意一個不是一個列表或元組.
  • RuntimeError:如果啟用了急切執(zhí)行.
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號