<h4 dir="auto">Description</h4>
<p dir="auto">sklearn.metrics.precision_score gives 0.0 when class is 0 only.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<p dir="auto">Example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from sklearn import metrics

y = [0,0,0]
y_pred = [0,0,0]
print(metrics.precision_score(y, y_pred)) # returns 0.0"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">sklearn</span> <span class="pl-k">import</span> <span class="pl-s1">metrics</span>

<span class="pl-s1">y</span> <span class="pl-c1">=</span> [<span class="pl-c1">0</span>,<span class="pl-c1">0</span>,<span class="pl-c1">0</span>]
<span class="pl-s1">y_pred</span> <span class="pl-c1">=</span> [<span class="pl-c1">0</span>,<span class="pl-c1">0</span>,<span class="pl-c1">0</span>]
<span class="pl-en">print</span>(<span class="pl-s1">metrics</span>.<span class="pl-en">precision_score</span>(<span class="pl-s1">y</span>, <span class="pl-s1">y_pred</span>)) <span class="pl-c"># returns 0.0</span></pre></div>
<h4 dir="auto">Expected Results</h4>
<p dir="auto">The expected result should be 1.0 because all the values are the same.</p>
<h4 dir="auto">Actual Results</h4>
<p dir="auto">The actual result is 0.0</p>
<h4 dir="auto">Versions</h4>
<p dir="auto">/usr/local/lib/python3.6/dist-packages/numpy/distutils/system_info.py:625: UserWarning:<br>
Atlas (<a href="http://math-atlas.sourceforge.net/" rel="nofollow">http://math-atlas.sourceforge.net/</a>) libraries not found.<br>
Directories to search for the libraries can be specified in the<br>
numpy/distutils/site.cfg file (section [atlas]) or by setting<br>
the ATLAS environment variable.<br>
self.calc_info()<br>
/usr/local/lib/python3.6/dist-packages/numpy/distutils/system_info.py:625: UserWarning:<br>
Blas (<a href="http://www.netlib.org/blas/" rel="nofollow">http://www.netlib.org/blas/</a>) libraries not found.<br>
Directories to search for the libraries can be specified in the<br>
numpy/distutils/site.cfg file (section [blas]) or by setting<br>
the BLAS environment variable.<br>
self.calc_info()<br>
/usr/local/lib/python3.6/dist-packages/numpy/distutils/system_info.py:625: UserWarning:<br>
Blas (<a href="http://www.netlib.org/blas/" rel="nofollow">http://www.netlib.org/blas/</a>) sources not found.<br>
Directories to search for the sources can be specified in the<br>
numpy/distutils/site.cfg file (section [blas_src]) or by setting<br>
the BLAS_SRC environment variable.<br>
self.calc_info()</p>
<h2 dir="auto">System</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="python: 3.6.6 (default, Sep 12 2018, 18:26:19)  [GCC 8.0.1 20180414 (experimental) [trunk revision 
259383]]
executable: /usr/local/bin/python
machine: Linux-4.4.0-17763-Microsoft-x86_64-with-Ubuntu-18.04-bionic"><pre class="notranslate"><code class="notranslate">python: 3.6.6 (default, Sep 12 2018, 18:26:19)  [GCC 8.0.1 20180414 (experimental) [trunk revision 
259383]]
executable: /usr/local/bin/python
machine: Linux-4.4.0-17763-Microsoft-x86_64-with-Ubuntu-18.04-bionic
</code></pre></div>
<h2 dir="auto">BLAS</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="macros:
lib_dirs:
cblas_libs: cblas"><pre class="notranslate"><code class="notranslate">macros:
lib_dirs:
cblas_libs: cblas
</code></pre></div>
<h2 dir="auto">Python deps</h2>
<p dir="auto">pip: 18.0<br>
setuptools: 39.2.0<br>
sklearn: 0.20.0<br>
numpy: 1.15.2<br>
scipy: 1.1.0<br>
Cython: 0.28.3<br>
pandas: 0.23.1</p>
<p dir="auto">I would be happy to help fix this if folks want.  For now, I'm just going to check if all values are zero and if they are, I'll return 1.0  Thanks!</p>
<h4 dir="auto">Description</h4>
<p dir="auto">precision_score shows incorrect value</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">A=np.array([[0,0,1],[0,1,0],[0,0,1]])<br>
B=A<br>
precision_score(A,B, average=None)<br>
array([ 0.,  1.,  1.])</p>
</blockquote>
</blockquote>
</blockquote>
<h4 dir="auto">Expected Results</h4>
<p dir="auto">array([ 1.,  1.,  1.])</p>
<h4 dir="auto">Actual Results</h4>
<p dir="auto">array([ 0.,  1.,  1.])</p>
<h4 dir="auto">Versions</h4>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">import platform; print(platform.platform())<br>
Darwin-14.5.0-x86_64-i386-64bit<br>
import sys; print("Python", sys.version)<br>
('Python', '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]')<br>
import numpy; print("NumPy", numpy.<strong>version</strong>)<br>
('NumPy', '1.13.3')<br>
import scipy; print("SciPy", scipy.<strong>version</strong>)<br>
('SciPy', '1.0.0')<br>
import sklearn; print("Scikit-Learn", sklearn.<strong>version</strong>)<br>
('Scikit-Learn', '0.18.1')</p>
</blockquote>
</blockquote>
</blockquote>