code: def calibration_histogram(
      num_buckets: Optional[int] = None,
      left: Optional[float] = None,
      right: Optional[float] = None,
      name: Optional[str] = None,
      eval_config: Optional[config_pb2.EvalConfig] = None,
      model_name: str = "",
      output_name: str = "",
      preprocessors: Optional[List[metric_types.Preprocessor]] = None,
      sub_key: Optional[metric_types.SubKey] = None,
      aggregation_type: Optional[metric_types.AggregationType] = None,
      class_weights: Optional[Dict[int, float]] = None,
      example_weighted: bool = False,
      prediction_based_bucketing: bool = True,
      fractional_labels: Optional[bool] = None,
  ) -> metric_types.MetricComputations:
      """Returns metric computations for calibration histogram.
  
      Args:
        num_buckets: Number of buckets to use. Note that the actual number of
          buckets will be num_buckets + 2 to account for the edge cases.
        left: Start of predictions interval.
        right: End of predictions interval.
        name: Metric name.
        eval_config: Eval config.
        model_name: Optional model name (if multi-model evaluation).
        output_name: Optional output name (if multi-output model type).
        preprocessors: A tfma component for preprocessing data.
        sub_key: Optional sub key.
        aggregation_type: Optional aggregation type.
        class_weights: Optional class weights to apply to multi-class / multi-label
          labels and predictions prior to flattening (when micro averaging is used).
        example_weighted:  True if example weights should be applied.
        prediction_based_bucketing: If true, create buckets based on predictions
          else use labels to perform bucketing.
        fractional_labels: If true, each incoming tuple of (label, prediction, and
          example weight) will be split into two tuples as follows (where l, p, w
          represent the resulting label, prediction, and example weight values): (1)
          l = 0.0, p = prediction, and w = example_weight * (1.0 - label) (2) l =
          1.0, p = prediction, and w = example_weight * label If enabled, an
          exception will be raised if labels are not within [0, 1]. The
          implementation is such that tuples associated with a weight of zero are
          not yielded. This means it is safe to enable fractional_labels even when
          the labels only take on the values of 0.0 or 1.0.
  
      Returns:
        MetricComputations for computing the histogram(s).
      """
      if num_buckets is None:
          num_buckets = DEFAULT_NUM_BUCKETS
      if left is None:
          left = 0.0
      if right is None:
          right = 1.0
      if fractional_labels is None:
          fractional_labels = left == 0.0 and right == 1.0
      if name is None:
          name_args = {
              "num_buckets": num_buckets,
              "left": left,
              "right": right,
              "fractional_labels": fractional_labels,
              "prediction_based_bucketing": prediction_based_bucketing,
          }
          if preprocessors:
              name_args["preprocessors"] = tuple(
                  p.name for p in preprocessors
              )
          if class_weights:
              name_args["class_weights"] = class_weights
          name = metric_util.generate_private_name_from_arguments(
              CALIBRATION_HISTOGRAM_NAME, **name_args
          )
      key = metric_types.PlotKey(
          name=name,
          model_name=model_name,
          output_name=output_name,
          sub_key=sub_key,
          example_weighted=example_weighted,
      )
      return [
          metric_types.MetricComputation(
              keys=[key],
              preprocessors=preprocessors,
              combiner=_CalibrationHistogramCombiner(
                  key=key,
                  eval_config=eval_config,
                  aggregation_type=aggregation_type,
                  class_weights=class_weights,
                  example_weighted=example_weighted,
                  num_buckets=num_buckets,
                  left=left,
                  right=right,
                  prediction_based_bucketing=prediction_based_bucketing,
                  fractional_labels=fractional_labels,
              ),
          )
      ]
  
file_path: model-analysis/tensorflow_model_analysis/metrics/calibration_histogram.py
imports: import dataclasses
  import operator
  from typing import Dict, Iterable, List, Optional
  import apache_beam
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: calibration_histogram(num_buckets, left, right, name, eval_config, model_name, output_name, preprocessors, sub_key, aggregation_type, class_weights, example_weighted, prediction_based_bucketing, fractional_labels) and returns: list