code: def test_multiclass_f1():
      microF1 = mx.gluon.metric.create(
          "f1", class_type="multiclass", average="micro"
      )
      macroF1 = mx.gluon.metric.F1(
          class_type="multiclass", average="macro"
      )
  
      assert np.isnan(macroF1.get()[1])
      assert np.isnan(microF1.get()[1])
  
      # check one class is zero
      pred = mx.np.array([[0.9, 0.1], [0.8, 0.2]])
      label = mx.np.array([0, 0])
      macroF1.update([label], [pred])
      microF1.update([label], [pred])
      assert (
          macroF1.get()[1] == 0.5
      )  # one class is 1.0, the other is 0. (divided by 0)
      assert microF1.get()[1] == 1.0  # globally f1 is 1.0
      macroF1.reset()
      microF1.reset()
  
      # test case from sklearn, here pred is probabilistic distributions instead of predicted labels
      pred11 = mx.np.array([[1, 0, 0], [0, 1, 0]])
      label11 = mx.np.array([0, 2])
      pred12 = mx.np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
      label12 = mx.np.array([1, 0, 0, 1])
  
      microF1.update([label11, label12], [pred11, pred12])
      macroF1.update([label11, label12], [pred11, pred12])
      assert microF1.num_inst == 6
      assert macroF1.num_inst == 6
  
      # from sklearn.metrics import f1_score
      # overall_pred = [0, 1, 2, 0, 1, 2]
      # overall_label = [0, 2, 1, 0, 0, 1]
      fmacro = 0.26666666666666666  # f1_score(overall_label, overall_pred, average="macro")
      fmicro = 0.3333333333333333  # f1_score(overall_label, overall_pred, average="micro")
      np.testing.assert_almost_equal(microF1.get()[1], fmicro)
      np.testing.assert_almost_equal(macroF1.get()[1], fmacro)
  
imports: import mxnet
  from mxnet.test_utils import use_np
  import numpy
  import scipy
  from scipy.stats import pearsonr
  import json
  import math
  from common import xfail_when_nonstandard_decimal_separator
  from copy import deepcopy
label_desc: Use image node_id 8 for calling a global function with example usage: test_multiclass_f1() without return types