---

title: stats

keywords: fastai
sidebar: home_sidebar

summary: "Módulo que contém os algoritmos para detecção de anomalias em dados univariados."
description: "Módulo que contém os algoritmos para detecção de anomalias em dados univariados."
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: 00_stats.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 %}

<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="Pr&#233;-requisitos">Pr&#233;-requisitos<a class="anchor-link" href="#Pr&#233;-requisitos"> </a></h2>
</div>
</div>
</div>
    {% 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="MAD---Robust-ZScore">MAD - Robust ZScore<a class="anchor-link" href="#MAD---Robust-ZScore"> </a></h2><p>Para detecção de anomalias o Zscore Robusto é mais adequado que o Zscore padrão, uma vez que a media pode ser fortemente influenciada por outliers.</p>

</div>
</div>
</div>
    {% 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 ">
<h2 id="MAD" class="doc_header"><code>class</code> <code>MAD</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L9" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>MAD</code>(<strong><code>only_low_values</code></strong>=<em><code>False</code></em>)</p>
</blockquote>
<p>classe responsavel por implemetar zscore robusto
para detecção de anomalias.</p>

</div>

</div>

</div>
</div>

</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="MAD.fit" class="doc_header"><code>MAD.fit</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L22" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>MAD.fit</code>(<strong><code>x</code></strong>)</p>
</blockquote>
<p>Calcula os parametros do Zscore Robusto(Median/MAD) para os valores de <strong>x</strong></p>

</div>

</div>

</div>
</div>

</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="MAD.predict" class="doc_header"><code>MAD.predict</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L27" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>MAD.predict</code>(<strong><code>x</code></strong>, <strong><code>m</code></strong>=<em><code>3.0</code></em>)</p>
</blockquote>
<p>retorna se os valores de <strong>x</strong> são outliers</p>

</div>

</div>

</div>
</div>

</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="MAD.fit_predict" class="doc_header"><code>MAD.fit_predict</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L45" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>MAD.fit_predict</code>(<strong><code>x</code></strong>, <strong><code>m</code></strong>=<em><code>3.0</code></em>)</p>
</blockquote>
<p>Calcula os parametros e retorno os valores
de <strong>x</strong> que são outliers</p>

</div>

</div>

</div>
</div>

</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="MAD.decision_function" class="doc_header"><code>MAD.decision_function</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L40" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>MAD.decision_function</code>(<strong><code>x</code></strong>)</p>
</blockquote>
<p>retorna se os valores de mad para cada valor em <strong>x</strong></p>

</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">
<h3 id="Uso">Uso<a class="anchor-link" href="#Uso"> </a></h3>
</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">x</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">randn</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span>
<span class="n">x</span><span class="p">[:</span><span class="mi">5</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.16827292,  0.7966477 , -0.61079429,  0.15528615,  0.70016939])</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">mad</span> <span class="o">=</span> <span class="n">MAD</span><span class="p">()</span>
<span class="n">mad</span><span class="o">.</span><span class="n">fit_predict</span><span class="p">(</span><span class="n">x</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([-3.26114306, -3.46102532,  3.83808166, -3.06892246, -3.14646764])</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">mad</span> <span class="o">=</span> <span class="n">MAD</span><span class="p">(</span><span class="n">only_low_values</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">mad</span><span class="o">.</span><span class="n">fit_predict</span><span class="p">(</span><span class="n">x</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([-3.26114306, -3.46102532, -3.06892246, -3.14646764])</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">
<h2 id="Tukey">Tukey<a class="anchor-link" href="#Tukey"> </a></h2>
</div>
</div>
</div>
    {% 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 ">
<h2 id="Tukey" class="doc_header"><code>class</code> <code>Tukey</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L52" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>Tukey</code>(<strong><code>only_low_values</code></strong>=<em><code>False</code></em>)</p>
</blockquote>
<p>classe responsavel por implemetar Tukey Method
para detecção de anomalias.</p>

</div>

</div>

</div>
</div>

</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="Tukey.fit" class="doc_header"><code>Tukey.fit</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L65" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>Tukey.fit</code>(<strong><code>x</code></strong>)</p>
</blockquote>
<p>Calcula os parametros do Tukey(Q1,Q2,Q3) para os valores de <strong>x</strong></p>

</div>

</div>

</div>
</div>

</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="Tukey.predict" class="doc_header"><code>Tukey.predict</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L79" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>Tukey.predict</code>(<strong><code>x</code></strong>)</p>
</blockquote>
<p>retorna se os valores de <strong>x</strong> são outliers</p>

</div>

</div>

</div>
</div>

</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="Tukey.decision_function" class="doc_header"><code>Tukey.decision_function</code><a href="https://github.com/fillipedem/pyanomaly/tree/master/pyanomaly/stats.py#L86" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>Tukey.decision_function</code>(<strong><code>x</code></strong>)</p>
</blockquote>
<p>retorna o score para os valores de <strong>x</strong></p>

</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">
<h3 id="Tukey-Uso">Tukey Uso<a class="anchor-link" href="#Tukey-Uso"> </a></h3>
</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">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>

<span class="n">tu</span> <span class="o">=</span> <span class="n">Tukey</span><span class="p">()</span>
<span class="n">tu</span><span class="o">.</span><span class="n">fit_predict</span><span class="p">(</span><span class="n">x</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([], dtype=int64)</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">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mi">100</span>
<span class="n">x</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span> <span class="o">=</span> <span class="mi">100</span>

<span class="n">tu</span> <span class="o">=</span> <span class="n">Tukey</span><span class="p">()</span>
<span class="n">tu</span><span class="o">.</span><span class="n">fit_predict</span><span class="p">(</span><span class="n">x</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([-100,  100])</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">tu</span> <span class="o">=</span> <span class="n">Tukey</span><span class="p">(</span><span class="n">only_low_values</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">tu</span><span class="o">.</span><span class="n">fit_predict</span><span class="p">(</span><span class="n">x</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([-100])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

</div>
 

