code: def confusion_to_weighted_f1(confusion_matrix, exclude=None):
      results = confusion_to_f1(confusion_matrix)
  
      sum_f1 = 0.0
      total_items = 0
      for k in results.keys():
          if exclude is not None and k in exclude:
              continue
          k_items = sum(confusion_matrix.get(k, {}).values())
          total_items += k_items
          sum_f1 += results[k].f1 * k_items
      return sum_f1 / total_items
  
imports: from collections import defaultdict, namedtuple
label_desc: Use image node_id 6 for calling a global function with example usage: confusion_to_weighted_f1(confusion_matrix, exclude) and returns: unknown