本文整理匯總了Python中tensorflow.python.ops.metrics_impl._confusion_matrix_at_thresholds方法的典型用法代碼示例。如果您正苦於以下問題:Python metrics_impl._confusion_matrix_at_thresholds方法的具體用法?Python metrics_impl._confusion_matrix_at_thresholds怎麽用?Python metrics_impl._confusion_matrix_at_thresholds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.ops.metrics_impl
的用法示例。
在下文中一共展示了metrics_impl._confusion_matrix_at_thresholds方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: confusion_matrix_metric_ops
# 需要導入模塊: from tensorflow.python.ops import metrics_impl [as 別名]
# 或者: from tensorflow.python.ops.metrics_impl import _confusion_matrix_at_thresholds [as 別名]
def confusion_matrix_metric_ops(
self,
features_dict: types.TensorTypeMaybeDict,
predictions_dict: types.TensorTypeMaybeDict,
labels_dict: types.TensorTypeMaybeDict,
) -> Tuple[Dict[Text, List[types.TensorType]], Dict[Text,
List[types.TensorType]]]:
"""Metric ops for computing confusion matrix at the given thresholds.
This is factored out because it's common to AucPlots and
ConfusionMatrixAtThresholds.
Args:
features_dict: Features dict.
predictions_dict: Predictions dict.
labels_dict: Labels dict.
Returns:
(value_ops, update_ops) for the confusion matrix.
"""
# Note that we have to squeeze predictions, labels, weights so they are all
# N element vectors (otherwise some of them might be N x 1 tensors, and
# multiplying a N element vector with a N x 1 tensor uses matrix
# multiplication rather than element-wise multiplication).
predictions, labels = self._get_labels_and_predictions(
predictions_dict, labels_dict)
prediction_tensor = _flatten_to_one_dim(tf.cast(predictions, tf.float64))
label_tensor = _flatten_to_one_dim(tf.cast(labels, tf.float64))
squeezed_weights = tf.ones_like(prediction_tensor)
if self._example_weight_key:
squeezed_weights = _flatten_to_one_dim(
tf.cast(features_dict[self._example_weight_key], tf.float64))
prediction_tensor, label_tensor, squeezed_weights = (
_create_predictions_labels_weights_for_fractional_labels(
prediction_tensor, label_tensor, squeezed_weights))
# TODO(b/72239826): Expose _confusion_matrix_at_thresholds for OSS?
values, update_ops = metrics_impl._confusion_matrix_at_thresholds( # pylint: disable=protected-access
label_tensor, prediction_tensor, self._thresholds, squeezed_weights)
values['precision'] = math.divide_no_nan(values['tp'],
(values['tp'] + values['fp']))
values['recall'] = math.divide_no_nan(values['tp'],
(values['tp'] + values['fn']))
return (values, update_ops) # pytype: disable=bad-return-type