tlby commented on issue #14461: [MXNET-1359] Adds a multiclass-MCC metric 
derived from Pearson
URL: https://github.com/apache/incubator-mxnet/pull/14461#issuecomment-475067430
 
 
   ```diff
   diff --git a/python/mxnet/metric.py b/python/mxnet/metric.py
   index 2a33cf4d9..6de76cc64 100644
   --- a/python/mxnet/metric.py
   +++ b/python/mxnet/metric.py
   @@ -1576,9 +1576,8 @@ class PCC(EvalMetric):
                n = max(pred.max(), label.max())
                if n >= self.k:
                    self._grow(n + 1 - self.k)
   -            bcm = numpy.zeros((self.k, self.k))
   -            for i, j in zip(pred, label):
   -                bcm[i, j] += 1
   +            ident = numpy.identity(self.k)
   +            bcm = numpy.tensordot(ident[label], ident[pred].T, axes=(0,1))
                self.lcm += bcm
                self.gcm += bcm
   ```
   seems more efficient for constructing the confusion matrix, but benchmarks 
worse.  I'm new to NumPy though, anyone see a better approach?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to