You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/04/16 15:41:51 UTC

[GitHub] [incubator-mxnet] sxjscience commented on a change in pull request #18083: Changes to mxnet.metric

sxjscience commented on a change in pull request #18083: Changes to mxnet.metric
URL: https://github.com/apache/incubator-mxnet/pull/18083#discussion_r409657973
 
 

 ##########
 File path: python/mxnet/gluon/metric.py
 ##########
 @@ -777,16 +815,113 @@ class F1(EvalMetric):
     --------
     >>> predicts = [mx.nd.array([[0.3, 0.7], [0., 1.], [0.4, 0.6]])]
     >>> labels   = [mx.nd.array([0., 1., 1.])]
-    >>> f1 = mx.metric.F1()
+    >>> f1 = mx.gluon.metric.F1()
     >>> f1.update(preds = predicts, labels = labels)
     >>> print f1.get()
     ('f1', 0.8)
     """
 
     def __init__(self, name='f1',
-                 output_names=None, label_names=None, average="macro"):
+                 output_names=None, label_names=None, threshold=0.5, average="macro"):
+        self.average = average
+        self.metrics = _BinaryClassificationMetrics(threshold=threshold)
+        EvalMetric.__init__(self, name=name,
+                            output_names=output_names, label_names=label_names,
+                            has_global_stats=True)
+
+    def update(self, labels, preds):
+        """Updates the internal evaluation result.
+
+        Parameters
+        ----------
+        labels : list of `NDArray`
+            The labels of the data.
+
+        preds : list of `NDArray`
+            Predicted values.
+        """
+        labels, preds = check_label_shapes(labels, preds, True)
+
+        for label, pred in zip(labels, preds):
+            self.metrics.update_binary_stats(label, pred)
+
+        if self.average == "macro":
 
 Review comment:
   In fact, `macro averaging` + F1 does not mean to average the F1 of each batch. I think we should revise it to be the same as https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html .

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services