code: def check_metrics(self, preds, labels, expected, metric_fn):
      # Check per-class metrics
      per_class_metrics = metric_fn(preds, labels)
      for cls, correct_metrics in expected["per_class_metrics"].items():
          metrics = per_class_metrics[cls]
          for metric in ("precision", "recall", "f1-score"):
              self.assertAlmostEqual(
                  metrics[metric],
                  correct_metrics[metric],
                  places=3,
                  msg=f"{metric} in {cls} is incorrect!",
              )
          for metric in (
              "true_positives",
              "false_positives",
              "false_negatives",
          ):
              self.assertEqual(
                  metrics[metric],
                  correct_metrics[metric],
                  msg=f"{metric} in {cls} is incorrect!",
              )
  
      # Check average metrics
      for avg, correct_f1 in expected["avg_f1"].items():
          avg_f1 = metric_fn(preds, labels, average=avg)
          self.assertAlmostEqual(
              avg_f1,
              correct_f1,
              places=3,
              msg=f"{avg} f1 in is incorrect!",
          )
  
imports: import unittest
  from copy import deepcopy
  from finetune.util.group_metrics import get_count_fn, calc_group_assignment, create_joint_groups, get_metrics, group_metrics, joint_metrics
label_desc: Use image node_id 18 for calling the TestGroupMetrics obj's underlying member method code with example usage: obj.check_metrics(preds, labels, expected, metric_fn) without return types