How to calculate a partial Area Under the Curve (AUC)
<p>In scikit learn you can compute the area under the curve for a binary classifier with</p>

<pre><code>roc_auc_score( Y, clf.predict_proba(X)[:,1] )
</code></pre>

<p>I am only interested in the part of the curve where the false positive rate is less than 0.1.</p>

<blockquote>
  <p>Given such a threshold false positive rate, how can I compute the AUC
  only for the part of the curve up the threshold?</p>
</blockquote>

<p>Here is an example with several ROC-curves, for illustration:</p>

<p><a href="http://i.stack.imgur.com/Xg4uc.png" rel="nofollow"><img src="http://i.stack.imgur.com/Xg4uc.png" alt="Illustration of ROC-curves plot for several types of a classifier."></a></p>

<p>The scikit learn docs show how to use roc_curve</p>

<pre><code>&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; from sklearn import metrics
&gt;&gt;&gt; y = np.array([1, 1, 2, 2])
&gt;&gt;&gt; scores = np.array([0.1, 0.4, 0.35, 0.8])
&gt;&gt;&gt; fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)
&gt;&gt;&gt; fpr
array([ 0. ,  0.5,  0.5,  1. ])
&gt;&gt;&gt; tpr
array([ 0.5,  0.5,  1. ,  1. ])
&gt;&gt;&gt; thresholds
array([ 0.8 ,  0.4 ,  0.35,  0.1 ]
</code></pre>

<p>Is there a simple way to go from this to the partial AUC?</p>

<hr>

<p>It seems the only problem is how to compute the tpr value at fpr = 0.1 as roc_curve doesn't necessarily give you that.</p>

<p>That depends on whether the FPR is the <strong>x</strong>-axis or <strong>y</strong>-axis (independent or dependent variable).</p>

<p>If it's <strong>x</strong>, the calculation is trivial: calculate only over the range [0.0, 0.1].</p>

<p>If it's <strong>y</strong>, then you first need to solve the curve for <strong>y = 0.1</strong>.  This partitions the x-axis into areas you need to calculate, and those that are simple rectangles with a height of 0.1.</p>

<p>For illustration, assume that you find the function exceeding 0.1 in two ranges: [x1, x2] and [x3, x4].  Calculate the area under the curve over the ranges</p>

<pre><code>[0, x1]
[x2, x3]
[x4, ...]
</code></pre>

<p>To this, add the rectangles under y=0.1 for the two intervals you found:</p>

<pre><code>area += (x2-x1 + x4-x3) * 0.1
</code></pre>

<p>Is that what you need to move you along?</p>

python machine-learning statistics scikit-learn