<p dir="auto"><a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/regression.py#L313">https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/regression.py#L313</a></p>
<p dir="auto">E..g, wrong in case y_true&gt;0 but y_pred&lt;=0.  One should have:</p>
<p dir="auto">if not (y_true &gt;= 0).all() or not (y_pred &gt;= 0).all():</p>
<p dir="auto">or</p>
<p dir="auto">if not ((y_true &gt;= 0).all() and (y_pred &gt;= 0).all()):</p>
<h4 dir="auto">Description</h4>
<p dir="auto">I found problem, where mean_squared_log_error() function does not catch error.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<p dir="auto">Imagine simple situation, where regression model predicts negative value:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np

y_true = np.array([1, 2, 3])
y_pred = np.array([1, -2, 3])
mean_squared_log_error(y_true, y_pred)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">y_true</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>])
<span class="pl-s1">y_pred</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">1</span>, <span class="pl-c1">-</span><span class="pl-c1">2</span>, <span class="pl-c1">3</span>])
<span class="pl-en">mean_squared_log_error</span>(<span class="pl-s1">y_true</span>, <span class="pl-s1">y_pred</span>)</pre></div>
<p dir="auto">This happened, when my regression model predicted 1 negative value (among thousands of positive values).</p>
<h4 dir="auto">Expected correct behavior:</h4>
<p dir="auto">Expected behavior is, that exception:<br>
<em>ValueError("Mean Squared Logarithmic Error cannot be used when targets contain negative values.")</em><br>
should be raised and correctly inform about the underlying problem.</p>
<h4 dir="auto">Exact location, where is the bug</h4>
<p dir="auto">Problematic code is exactly in sklearn/metrics/regression.py: (around line 313)</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if not (y_true &gt;= 0).all() and not (y_pred &gt;= 0).all():
        raise ValueError(&quot;Mean Squared Logarithmic Error cannot be used when &quot;
                         &quot;targets contain negative values.&quot;)"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-c1">not</span> (<span class="pl-s1">y_true</span> <span class="pl-c1">&gt;=</span> <span class="pl-c1">0</span>).<span class="pl-en">all</span>() <span class="pl-c1">and</span> <span class="pl-c1">not</span> (<span class="pl-s1">y_pred</span> <span class="pl-c1">&gt;=</span> <span class="pl-c1">0</span>).<span class="pl-en">all</span>():
        <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">"Mean Squared Logarithmic Error cannot be used when "</span>
                         <span class="pl-s">"targets contain negative values."</span>)</pre></div>
<p dir="auto">The condition is not fully correct and evaluates to False for example above - which is wrong.<br>
It should evaluate to True, and raise the exception.</p>
<h4 dir="auto">Suggested solution:</h4>
<p dir="auto">Just change the condition to:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if (y_true &lt; 0).any() or (y_pred &lt; 0).any():
        raise ValueError(&quot;Mean Squared Logarithmic Error cannot be used when &quot;
                         &quot;targets contain negative values.&quot;)"><pre class="notranslate"><span class="pl-k">if</span> (<span class="pl-s1">y_true</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">0</span>).<span class="pl-en">any</span>() <span class="pl-c1">or</span> (<span class="pl-s1">y_pred</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">0</span>).<span class="pl-en">any</span>():
        <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">"Mean Squared Logarithmic Error cannot be used when "</span>
                         <span class="pl-s">"targets contain negative values."</span>)</pre></div>
<p dir="auto">so it catches the problem in case any of the <strong>y_true</strong> or <strong>y_pred</strong> contain negative value.</p>