code: def test_binary_f1():
      microF1 = mx.gluon.metric.create("f1", average="micro")
      macroF1 = mx.gluon.metric.F1(average="macro")
  
      assert np.isnan(macroF1.get()[1])
      assert np.isnan(microF1.get()[1])
  
      # check divide by 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.0
      assert microF1.get()[1] == 0.0
      macroF1.reset()
      microF1.reset()
  
      pred11 = mx.np.array([[0.1, 0.9], [0.5, 0.5]])
      label11 = mx.np.array([1, 0])
      pred12 = mx.np.array([[0.85, 0.15], [1.0, 0.0]])
      label12 = mx.np.array([1, 0])
      pred21 = mx.np.array([[0.6, 0.4]])
      label21 = mx.np.array([0])
      pred22 = mx.np.array([[0.2, 0.8]])
      label22 = mx.np.array([1])
  
      microF1.update([label11, label12], [pred11, pred12])
      macroF1.update([label11, label12], [pred11, pred12])
      assert microF1.num_inst == 4
      assert macroF1.num_inst == 4
      # f1 = 2 * tp / (2 * tp + fp + fn)
      fscore1 = 2.0 * (1) / (2 * 1 + 1 + 0)
      np.testing.assert_almost_equal(microF1.get()[1], fscore1)
      np.testing.assert_almost_equal(macroF1.get()[1], fscore1)
  
      microF1.update([label21, label22], [pred21, pred22])
      macroF1.update([label21, label22], [pred21, pred22])
      assert microF1.num_inst == 6
      assert macroF1.num_inst == 6
      fscore2 = 2.0 * (1) / (2 * 1 + 0 + 0)
      fscore_total = 2.0 * (1 + 1) / (2 * (1 + 1) + (1 + 0) + (0 + 0))
      np.testing.assert_almost_equal(microF1.get()[1], fscore_total)
      np.testing.assert_almost_equal(macroF1.get()[1], fscore_total)
  
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 7 for calling a global function with example usage: test_binary_f1() without return types