---

title: NumPy Evaluation Metrics


keywords: fastai
sidebar: home_sidebar

summary: "Metrics for evaluation."
description: "Metrics for evaluation."
nb_path: "nbs/losses__numpy.ipynb"
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: nbs/losses__numpy.ipynb
# command to build the docs after a change: nbdev_build_docs

-->

<div class="container" id="notebook-container">
        
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="divide_no_nan" class="doc_header"><code>divide_no_nan</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L13" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>divide_no_nan</code>(<strong><code>a</code></strong>, <strong><code>b</code></strong>)</p>
</blockquote>
<p>Auxiliary funtion to handle divide by 0</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="metric_protections" class="doc_header"><code>metric_protections</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L23" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>metric_protections</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>ndarray</code>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="mape" class="doc_header"><code>mape</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L28" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>mape</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates Mean Absolute Percentage Error.</p>
<p>MAPE measures the relative prediction accuracy of a
forecasting method by calculating the percentual deviation
of the prediction and the true value at a given time and
averages these devations over the length of the series.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array
    Predicted values.
weights: numpy array, optional
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>mape: numpy array or double
    Return the mape along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="mse" class="doc_header"><code>mse</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L69" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>mse</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates Mean Squared Error.</p>
<p>MSE measures the prediction accuracy of a
forecasting method by calculating the squared deviation
of the prediction and the true value at a given time and
averages these devations over the length of the series.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array
    Predicted values.
weights: numpy array
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>mse: numpy array or double
    Return the mse along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="rmse" class="doc_header"><code>rmse</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L112" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>rmse</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates Root Mean Squared Error.</p>
<p>RMSE measures the prediction accuracy of a
forecasting method by calculating the squared deviation
of the prediction and the true value at a given time and
averages these devations over the length of the series.
Finally the RMSE will be in the same scale
as the original time series so its comparison with other
series is possible only if they share a common scale.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array
    Predicted values.
weights: numpy array
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>rmse: numpy array or double
    Return the rmse along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="smape" class="doc_header"><code>smape</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L149" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>smape</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates Symmetric Mean Absolute Percentage Error.</p>
<p>SMAPE measures the relative prediction accuracy of a
forecasting method by calculating the relative deviation
of the prediction and the true value scaled by the sum of the
absolute values for the prediction and true value at a
given time, then averages these devations over the length
of the series. This allows the SMAPE to have bounds between
0% and 200% which is desireble compared to normal MAPE that
may be undetermined.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array
    Predicted values.
weights: numpy array
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>smape: numpy array or double
    Return the smape along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="mase" class="doc_header"><code>mase</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L198" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>mase</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>y_train</code></strong>:<code>ndarray</code>, <strong><code>seasonality</code></strong>:<code>int</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates the Mean Absolute Scaled Error.</p>
<p>MASE measures the relative prediction accuracy of a
forecasting method by comparinng the mean absolute errors
of the prediction and the true value against the mean
absolute errors of the seasonal naive model.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array
    Predicted values.
y_train: numpy array
    Actual insample values for Seasonal Naive predictions.
seasonality: int
    Main frequency of the time series
    Hourly 24,  Daily 7, Weekly 52,
    Monthly 12, Quarterly 4, Yearly 1.
weights: numpy array
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>mase: numpy array or double
    Return the mase along the specified axis.</p>
<h2 id="References">References<a class="anchor-link" href="#References"> </a></h2><p>[1] <a href="https://robjhyndman.com/papers/mase.pdf">https://robjhyndman.com/papers/mase.pdf</a></p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="mae" class="doc_header"><code>mae</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L251" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>mae</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates Mean Absolute Error.</p>
<p>The mean absolute error</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array
    Predicted values.
weights: numpy array
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>mae: numpy array or double
    Return the mae along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="pinball_loss" class="doc_header"><code>pinball_loss</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L291" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>pinball_loss</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>tau</code></strong>:<code>float</code>=<em><code>0.5</code></em>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates the Pinball Loss.</p>
<p>The Pinball loss measures the deviation of a quantile forecast.
By weighting the absolute deviation in a non symmetric way, the
loss pays more attention to under or over estimation.
A common value for tau is 0.5 for the deviation from the median.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array
    Predicted values.
weights: numpy array
    Weights for weighted average.
tau: float
    Fixes the quantile against which the predictions are compared.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>pinball loss: numpy array or double
    Return the pinball loss along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="rmae" class="doc_header"><code>rmae</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L338" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>rmae</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat1</code></strong>:<code>ndarray</code>, <strong><code>y_hat2</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates Relative Mean Absolute Error.</p>
<p>The relative mean absolute error of two forecasts.
A number smaller than one implies that the forecast in the
numerator is better than the forecast in the denominator.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat1: numpy array
    Predicted values of first model.
y_hat2: numpy array
    Predicted values of second model.
weights: numpy array
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>rmae: numpy array or double
    Return the rmae along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Multi-quantile-NumPy-loss">Multi-quantile NumPy loss<a class="anchor-link" href="#Multi-quantile-NumPy-loss"> </a></h2><p>MQLoss definition and testing.</p>

</div>
</div>
</div>
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="mqloss" class="doc_header"><code>mqloss</code><a href="https://github.com/Nixtla/nixtlats/tree/master/nixtlats/losses/numpy.py#L377" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>mqloss</code>(<strong><code>y</code></strong>:<code>ndarray</code>, <strong><code>y_hat</code></strong>:<code>ndarray</code>, <strong><code>quantiles</code></strong>:<code>ndarray</code>, <strong><code>weights</code></strong>:<code>Optional</code>[<code>ndarray</code>]=<em><code>None</code></em>, <strong><code>axis</code></strong>:<code>Optional</code>[<code>int</code>]=<em><code>None</code></em>)</p>
</blockquote>
<p>Calculates the MultiQuantile loss.</p>
<p>Calculates Average Multi-quantile Loss function, for
a given set of quantiles, based on the absolute
difference between predicted and true values.</p>
<h2 id="Parameters">Parameters<a class="anchor-link" href="#Parameters"> </a></h2><p>y: numpy array
    Actual test values.
y_hat: numpy array (-1, n_quantiles)
    Predicted values.
quantiles: numpy array (n_quantiles)
    Quantiles to estimate from the distribution of y.
weights: numpy array
    Weights for weighted average.
axis: None or int, optional
    Axis or axes along which to average a.
    The default, axis=None, will average over all of the
    elements of the input array.
    If axis is negative it counts
    from the last to the first axis.</p>
<h2 id="Returns">Returns<a class="anchor-link" href="#Returns"> </a></h2><p>mqloss: numpy array or double
    Return the mqloss along the specified axis.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">7</span><span class="p">))</span>
<span class="n">y_q</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
<span class="n">weights</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones_like</span><span class="p">(</span><span class="n">y_q</span><span class="p">)</span>
<span class="n">quantiles</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">])</span>

<span class="n">mqloss</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">y_q</span><span class="p">,</span> <span class="n">quantiles</span><span class="p">,</span> <span class="n">weights</span><span class="o">=</span><span class="n">weights</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>array([0.21041164, 0.15391882, 0.09449471, 0.18244145, 0.16071395,
       0.13142336, 0.20231349, 0.19795971, 0.15299534, 0.16744432,
       0.13345362, 0.16700624, 0.10257573, 0.16436093, 0.16341954,
       0.15676824, 0.20708862, 0.15711264, 0.21645739, 0.17206218,
       0.23661543, 0.16738924, 0.1577535 , 0.16585761, 0.16793635,
       0.15740434, 0.13467679, 0.21414516, 0.14007157, 0.27435823,
       0.20451858, 0.11715621, 0.12763097, 0.2100278 , 0.10294569,
       0.16492288, 0.11550836, 0.19200599, 0.12251248, 0.17777111,
       0.20632066, 0.25534812, 0.22850697, 0.2117134 , 0.20114755,
       0.22731604, 0.15800838, 0.17286858, 0.14366458, 0.14034129,
       0.20393408, 0.13572314, 0.24699116, 0.17890431, 0.11960552,
       0.11549357, 0.13940521, 0.13799181, 0.21941735, 0.10874776,
       0.16519921, 0.12306689, 0.1858083 , 0.11227548, 0.14478089,
       0.23283138, 0.16608539, 0.2198971 , 0.23463294, 0.22970342,
       0.16031605, 0.16675414, 0.17982392, 0.13855352, 0.22509618,
       0.18950097, 0.2207443 , 0.15073855, 0.19502465, 0.16299692,
       0.11750915, 0.17005201, 0.17436329, 0.17390164, 0.14895287,
       0.14644051, 0.10446581, 0.13071105, 0.13252147, 0.10070003,
       0.1649476 , 0.28120334, 0.13300598, 0.19693479, 0.16165529,
       0.184198  , 0.19409348, 0.14772852, 0.11654125, 0.16790548])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">mqloss</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">y_q</span><span class="p">,</span> <span class="n">quantiles</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>0.16948741448706903</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Checks-for-NumPy-Evaluation-Metrics">Checks for NumPy Evaluation Metrics<a class="anchor-link" href="#Checks-for-NumPy-Evaluation-Metrics"> </a></h1>
</div>
</div>
</div>
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">])</span>
<span class="n">y_mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
<span class="n">y_hat</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mi">7</span><span class="p">,</span><span class="o">-</span><span class="mi">8</span><span class="p">,</span><span class="o">-</span><span class="mi">9</span><span class="p">,</span><span class="o">-</span><span class="mi">10</span><span class="p">])</span>

<span class="nb">print</span><span class="p">(</span><span class="n">mae</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">y_hat</span><span class="o">=</span><span class="n">y_hat</span><span class="p">,</span> <span class="n">weights</span><span class="o">=</span><span class="n">y_mask</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">mae</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">y_hat</span><span class="o">=</span><span class="n">y_hat</span><span class="p">))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>5.3
4.777777777777778
</pre>
</div>
</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">mae</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">y_hat</span><span class="o">=</span><span class="n">y_hat</span><span class="p">,</span> <span class="n">weights</span><span class="o">=</span><span class="n">y_mask</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">mae</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">y_hat</span><span class="o">=</span><span class="n">y_hat</span><span class="p">))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>5.3
4.777777777777778
</pre>
</div>
</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>10</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

</div>
 

