当前位置: 首页>>代码示例>>Python>>正文


Python metrics_impl._confusion_matrix_at_thresholds方法代码示例

本文整理汇总了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 
开发者ID:tensorflow,项目名称:model-analysis,代码行数:47,代码来源:post_export_metrics.py


注:本文中的tensorflow.python.ops.metrics_impl._confusion_matrix_at_thresholds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。