<h4 dir="auto">Description</h4>
<p dir="auto">Log_loss uses LabelBibarizer to transform only original y_true, but not to transform y_pred.<br>
Hence array y_true=[1,1,1]  is transformed into [0,0,0], while y_pred is unchanged. This makes the result to be quite different from expected.</p>
<h4 dir="auto">Sample code</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from sklearn.metrics import log_loss
y_true = [1,1,1]
y_pred = [0,0,0]
print(log_loss(y_true,y_pred))  # incorrect, because y_true is transformed into [0,0,0]
print(log_loss(y_pred,y_true))  # correct"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">metrics</span> <span class="pl-k">import</span> <span class="pl-s1">log_loss</span>
<span class="pl-s1">y_true</span> <span class="pl-c1">=</span> [<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</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-en">log_loss</span>(<span class="pl-s1">y_true</span>,<span class="pl-s1">y_pred</span>))  <span class="pl-c"># incorrect, because y_true is transformed into [0,0,0]</span>
<span class="pl-en">print</span>(<span class="pl-en">log_loss</span>(<span class="pl-s1">y_pred</span>,<span class="pl-s1">y_true</span>))  <span class="pl-c"># correct</span></pre></div>
<h4 dir="auto">Expected Results</h4>
<p dir="auto">34.5395759923<br>
34.5395759923</p>
<h4 dir="auto">Actual Results</h4>
<p dir="auto">9.99200722163e-16<br>
34.5395759923</p>
<h4 dir="auto">Versions</h4>
<p dir="auto">Windows-7-6.1.7601-SP1<br>
Python 3.4.4 |Anaconda 2.3.0 (64-bit)| (default, Feb 16 2016, 09:54:04) [MSC v.1600 64 bit (AMD64)]<br>
NumPy 1.10.4<br>
SciPy 0.16.0<br>
Scikit-Learn 0.16.1</p>
<p dir="auto">When there is only one class, such as :</p>
<p dir="auto">y_true = np.array(['class1', 'class1', 'class1'])<br>
y_predict = np.array([[0.1],[0.7],[0.5]])<br>
log_loss(y_true, y_predict)</p>
<p dir="auto">The result would be wrong, which is not the logloss of y_predict but the logloss of 1-y_predict</p>
<p dir="auto">The code in log_loss:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="if Y.shape[1] == 1:
    Y = np.append(1 - Y, Y, axis=1)"><pre class="notranslate"><code class="notranslate">if Y.shape[1] == 1:
    Y = np.append(1 - Y, Y, axis=1)
</code></pre></div>
<p dir="auto">should be change to :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="if Y.shape[1] == 1:
    Y = np.append(Y, 1 - Y, axis=1)"><pre class="notranslate"><code class="notranslate">if Y.shape[1] == 1:
    Y = np.append(Y, 1 - Y, axis=1)
</code></pre></div>