title: auc calculation based on Mann–Whitney U does not match with other formulas
body: <p>From <a href="https://en.wikipedia.org/wiki/Receiver_operating_characteristic" rel="nofollow noreferrer">wikipedia</a>:</p>
  <blockquote>
  <p>Area under the curve It can be shown that the AUC is closely related
  to the Mann–Whitney U,[28][29] which tests whether positives are
  ranked higher than negatives. It is also equivalent to the Wilcoxon
  test of ranks.[29] For a predictor {\textstyle f}{\textstyle f}, an
  unbiased estimator of its AUC can be expressed by the following
  Wilcoxon-Mann-Whitney statistic:[30]</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/91Mrh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/91Mrh.png" alt="enter image description here" /></a></p>
  <p>But as i try it manually or using code does not match with scikit learn implemenataion of auc.</p>
  <pre><code>labels = np.random.randint(0,2,5)
  preds = [abs(x) for x in np.random.choice(imb_data, size = len(labels))]
  fpr, tpr, thresholds = metrics.roc_curve(labels, preds, pos_label=1)
  scikit_auc = metrics.auc(fpr, tpr) 
  
  def auc(f, D):
      D = np.array(D)
      D0 = np.where(D==0)
      D1 = np.where(D==1)
      sum_ = 0
      for t0 in D0[0]:
          for t1 in D1[0]:
              if f[t0]&lt;f[t1]:
                  sum_+=1
      return sum_/(len(D0[0])*len(D1[0]))
  auc(preds, labels)
  
  f&quot;auc based on wikipedia: {auc(preds, labels)}, and based on scikit: {scikit_auc}&quot;
  </code></pre>
  <p>Output:</p>
  <p>'auc based on wikipedia: 0.0, and based on scikit: 0.25'</p>
  <p>Also, it seems that scikit is using <code>np.trapz</code> under hood. And it matches:</p>
  <pre><code>np.trapz(tpr, fpr)
  </code></pre>
  <p>Which is consistent with visualization of data too.</p>
  <p><a href="https://i.stack.imgur.com/1UAxe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1UAxe.png" alt="enter image description here" /></a></p>