<p dir="auto">In the <code class="notranslate">sklearn.metrics.precision_recall_curve</code> documentation,</p>
<blockquote>
<p dir="auto">thresholds : array, shape = [n_thresholds := len(np.unique(probas_pred))]</p>
</blockquote>
<p dir="auto">But as the example below shows,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; y_scores = np.array([0.1, 0.4, 0.35, 0.8])
...
&gt;&gt;&gt; thresholds
array([ 0.35,  0.4 ,  0.8 ])"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; y_scores = np.array([0.1, 0.4, 0.35, 0.8])
...
&gt;&gt;&gt; thresholds
array([ 0.35,  0.4 ,  0.8 ])
</code></pre></div>
<p dir="auto">the shape of threshold is not <code class="notranslate">len(np.unique(probas_pred))</code>.</p>
<p dir="auto">Referencing <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/ranking.py#L346-L348"><code class="notranslate">"The last precision and recall values are 1. and 0. respectively and do not have a corresponding threshold. This ensures that the graph starts on the x axis."</code></a></p>
<p dir="auto">Say you have a tie in your highest predicted probability output from the classifier with some false positives and some true positives, for example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="y_true = [ 1,  0,  0,  1,  0,  1,  0,  0,  0,  1,  0]
y_pred = [.9, .9, .9, .8, .8, .7, .7, .6, .5, .4, .3]
precision, recall, thresholds = precision_recall_curve(y_true, y_pred)"><pre class="notranslate"><code class="notranslate">y_true = [ 1,  0,  0,  1,  0,  1,  0,  0,  0,  1,  0]
y_pred = [.9, .9, .9, .8, .8, .7, .7, .6, .5, .4, .3]
precision, recall, thresholds = precision_recall_curve(y_true, y_pred)
</code></pre></div>
<p dir="auto">Yields:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Pricision: [0.400, 0.333, 0.375, 0.428, 0.400, 0.333, 1.000]
Recall:    [1.000, 0.750, 0.750, 0.750, 0.500, 0.250, 0.000]"><pre class="notranslate"><code class="notranslate">Pricision: [0.400, 0.333, 0.375, 0.428, 0.400, 0.333, 1.000]
Recall:    [1.000, 0.750, 0.750, 0.750, 0.500, 0.250, 0.000]
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/5210848/6098145/7fb45fec-af8a-11e4-9e21-7549071fb2b3.png"><img src="https://cloud.githubusercontent.com/assets/5210848/6098145/7fb45fec-af8a-11e4-9e21-7549071fb2b3.png" alt="download 1" style="max-width: 100%;"></a></p>
<p dir="auto">I understand that recall goes to zero in the limit, but precision might not be so clear-cut. A <em>really</em> difficult problem where your top prediction is a false positive would have precision go to zero in the limit I believe. For plotting with this function, this case is probably not a big deal a vertical line from 0 to 1 would be hidden by the y-axis.</p>
<p dir="auto">But for the drawn top-preds, as seen above, the plot becomes misleading and makes the viewer think that at least their top prediction was true positive. This may seem like a corner case, but I ran into it on a tough classification problem I was working on and was a little baffled by the output until I checked the code out.</p>
<p dir="auto">A quick fix to preserve the intention of a clean P-R plot might be to draw a horizontal line from the highest threshold to the y-axis, this should not alter the output of most cases like <a href="http://scikit-learn.org/stable/auto_examples/plot_precision_recall.html" rel="nofollow">here</a>. Trying to actually calculate where it's going in the limit might be a bit overkill :-)</p>
<p dir="auto">I would also think that adding a <code class="notranslate">1</code> to the end of the <code class="notranslate">thresholds</code> vector would be helpful when plotting both precision and recall against the probabilities.</p>
<p dir="auto">I'm happy to open a PR if anyone thinks this is worth addressing.</p>