code: def calculate_metrics(output_dir):
      # reorder regions
      raw_results = parse_all(datapath=output_dir)
  
      # compressing results:
      # - removing label info
      # - for each image, counting hit and cover as max over possible labels
      # - average hits and covers over households.
      # image
      # new_results = results.groupby(by=COLUMNS_COMPRESSED + ["image"])[["hit", "cover"]].max().reset_index()
      # households
      raw_results_hh = (
          raw_results.groupby(by=COLUMNS_COMPRESSED)[["hit", "cover"]]
          .mean()
          .reset_index()
      )
  
      # income buckets
      raw_results = add_log_income(raw_results)
      raw_results_hh = add_log_income(raw_results_hh)
  
      raw_results["region"] = raw_results["region"].astype(_region_type)
      raw_results["archname"] = (
          raw_results["architecture"]
          .apply(lambda x: ARCH_NAMES[x])
          .astype(_model_type)
      )
      raw_results["trname"] = (
          raw_results["training"]
          .apply(lambda x: TRAINING_NAMES[x])
          .astype(_training_type)
      )
      raw_results["sz"] = (
          raw_results["data_size"]
          .apply(lambda x: SIZE_NAMES[x])
          .astype(_size_type)
      )
      raw_results["income bucket"] = raw_results[
          "income_bucket"
      ].astype(_income_type)
  
      print(raw_results_hh["architecture"])
      raw_results_hh["region"] = raw_results_hh["region"].astype(
          _region_type
      )
      raw_results_hh["archname"] = (
          raw_results_hh["architecture"]
          .apply(lambda x: ARCH_NAMES[x])
          .astype(_model_type)
      )
      raw_results_hh["trname"] = (
          raw_results_hh["training"]
          .apply(lambda x: TRAINING_NAMES[x])
          .astype(_training_type)
      )
      raw_results_hh["sz"] = (
          raw_results_hh["data_size"]
          .apply(lambda x: SIZE_NAMES[x])
          .astype(_size_type)
      )
      raw_results_hh["income bucket"] = raw_results_hh[
          "income_bucket"
      ].astype(_income_type)
  
      # model size ig1b
      _plot_ir(
          raw_results_hh.query(
              'training=="seer" & data_size=="1b"'
          ).sort_values(by="archname"),
          model_name_string="{trname} - {archname}",
          figname="/tmp/dollar_street_models/my-model.png",
      )
  
imports: import json
  import os
  from math import ceil, floor
  from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pandas
  import seaborn
  from IPython.display import display_html
  from matplotlib.ticker import FixedLocator
  from vissl.utils.io import load_file, save_file
label_desc: Use image node_id 14 for calling a global function with example usage: calculate_metrics(output_dir) without return types