<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/anomalize-tidy-anomaly-detection/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.business-science.io/code-tools/2018/04/08/introducing-anomalize.html"> business-science.io - Articles</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>We recently had an awesome opportunity to work with a great client that asked <strong>Business Science</strong> to build an <strong>open source anomaly detection algorithm</strong> that suited their needs. The business goal was to accurately detect anomalies for various marketing data consisting of website actions and marketing feedback spanning thousands of time series across multiple customers and web sources. Enter <code>anomalize</code>: <strong>a tidy anomaly detection algorithm that’s time-based (built on top of <code>tibbletime</code>) and scalable from one to many time series</strong>!! We are really excited to present this open source R package for others to benefit. In this post, we’ll go through an overview of what <code>anomalize</code> does and how it works.</p>
<h2>Case Study: When Open Source Interests Align</h2>
<p>We work with many clients teaching data science and using our expertise to accelerate their business. However, it’s rare to have a client’s needs and their willingness to let others benefit align with our interests of pushing the boundaries of data science. This was an exception.</p>
<p>Our client had a challenging problem: <strong>detecting anomalies in time series on daily or weekly data at scale</strong>. Anomalies indicate exceptional events, which could be increased web traffic in the marketing domain or a malfunctioning server in the IT domain. Regardless, it’s important to flag these unusual occurrences to ensure the business is running smoothly. One of the challenges was that the client deals with not one time series but <strong>thousands that need to be analyzed for these extreme events</strong>.</p>
<p>An opportunity presented itself to develop an open source package that aligned with our interests of building a scalable adaptation of the <a rel="nofollow" href="https://github.com/twitter/AnomalyDetection" target="_blank">Twitter <code>AnomalyDetection</code> package</a> and our client’s desire for a package that would benefit from the open source data science community’s ability to improve over time. The result is <code>anomalize</code>!!!</p>
<h2>2 Minutes To Anomalize</h2>
<p>We’ve made a short introductory video that’s part of our new Business Science Software Intro Series on YouTube. This will get you up and running in under 2 minutes.</p>
<p><iframe allowfullscreen src="https://www.youtube.com/embed/Gk_HwjhlQJs" width="100%" height="500"></iframe></p>
<p>For those of us who prefer to read, here’s the gist of how <code>anomalize</code> works in four simple steps.</p>
<h3>Step 1: Install Anomalize</h3>
<figure>
<pre><code data-lang="r"><span>install.packages</span><span>(</span><span>&quot;anomalize&quot;</span><span>)</span></code></pre>
</figure>
<h3>Step 2: Load Tidyverse and Anomalize</h3>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>anomalize</span><span>)</span></code></pre>
</figure>
<h3>Step 3: Collect Time Series Data</h3>
<p>We’ve provided a dataset, <code>tidyverse_cran_downloads</code>, to get you up and running. The dataset consists of daily download counts of 15 “tidyverse” packages.</p>
<figure>
<pre><code data-lang="r"><span>tidyverse_cran_downloads</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## # A tibble: 6,375 x 3
## # Groups:   package [15]
##    date       count package
##    </code></pre></figure>