本文整理汇总了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