szha commented on a change in pull request #9833: [Metric] Accelerate the calculation of F1 URL: https://github.com/apache/incubator-mxnet/pull/9833#discussion_r169199762
########## File path: python/mxnet/metric.py ########## @@ -510,16 +510,10 @@ def update_binary_stats(self, label, pred): if len(numpy.unique(label)) > 2: raise ValueError("%s currently only supports binary classification." % self.__class__.__name__) - - for y_pred, y_true in zip(pred_label, label): - if y_pred == 1 and y_true == 1: - self.true_positives += 1. - elif y_pred == 1 and y_true == 0: - self.false_positives += 1. - elif y_pred == 0 and y_true == 1: - self.false_negatives += 1. - else: - self.true_negatives += 1. + self.true_positives += ((pred_label == 1) * (label == 1)).sum() Review comment: you can cache the computation such as `predicted_true = pred_label == 1` and use later. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services