code: def _expected_stats(all_classes_counts: Dict[str, Dict[str, int]]):
      micro_counts: Dict[str, int] = defaultdict(int)
      for class_counts in all_classes_counts.values():
          for key, class_count in class_counts.items():
              micro_counts[key] += class_count
      micro_precision = micro_counts["tp"] / (
          micro_counts["tp"] + micro_counts["fp"]
      )
      micro_recall = micro_counts["tp"] / (
          micro_counts["tp"] + micro_counts["fn"]
      )
      micro_f1 = (
          2
          * (micro_precision * micro_recall)
          / (micro_precision + micro_recall)
      )
  
      class_f1: List[float] = []
      for class_counts in all_classes_counts.values():
          class_precision = class_counts["tp"] / (
              class_counts["tp"] + class_counts["fp"]
          )
          class_recall = class_counts["tp"] / (
              class_counts["tp"] + class_counts["fn"]
          )
          class_f1.append(
              2
              * (class_precision * class_recall)
              / (class_precision + class_recall)
          )
      macro_f1 = sum(class_f1) / len(class_f1)
  
      return {
          "classification_micro_f1": micro_f1,
          "classification_macro_f1": macro_f1,
      }
  
file_path: H2O/h2o_hf/helm/src/helm/benchmark/metrics/test_classification_metrics.py
imports: from collections import defaultdict
  from typing import Dict, List, NamedTuple
  from pytest import approx
  from helm.benchmark.adaptation.request_state import RequestState
  from helm.benchmark.metrics.classification_metrics import ClassificationMetric
  from helm.benchmark.metrics.statistic import Stat
  from helm.benchmark.scenarios.scenario import Input, Instance, Output, Reference, CORRECT_TAG
  from helm.common.request import Request, RequestResult, Sequence
label_desc: Use image node_id 3 for calling a global function with example usage: _expected_stats(all_classes_counts) and returns: dict