From commits-return-23676-archive-asf-public=cust-asf.ponee.io@mxnet.incubator.apache.org Tue Feb 20 02:24:16 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7F313180607 for ; Tue, 20 Feb 2018 02:24:15 +0100 (CET) Received: (qmail 46180 invoked by uid 500); 20 Feb 2018 01:24:14 -0000 Mailing-List: contact commits-help@mxnet.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mxnet.incubator.apache.org Delivered-To: mailing list commits@mxnet.incubator.apache.org Received: (qmail 46170 invoked by uid 99); 20 Feb 2018 01:24:14 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Feb 2018 01:24:14 +0000 From: GitBox To: commits@mxnet.apache.org Subject: [GitHub] szha commented on a change in pull request #9833: [Metric] Accelerate the calculation of F1 Message-ID: <151908985398.1024.2601068298029735571.gitbox@gitbox.apache.org> 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: users@infra.apache.org With regards, Apache Git Services