Seasonality and anomalies in time series data
1. Date transformations and visualizations
Welcome back. In this chapter, we'll be diving into an exploration of seasonality and how to detect this, as well as how to make use of Tableau's percentile functions to identify anomalous values.2. What's seasonality?
Seasonality is a concept you've likely heard of. In a nut shell, it's a characteristic of time series in which the data experiences regular and predictable changes that recur every calendar year. Seasonal examples include tourism or fruiting seasons that have variable prices based off timing. If we look at the visual, we can see the same period spikes and declines time and time again for Avocados. Now regular and predictable changes are critical because, if a business can understand this, they can scale their operations up or down as needed.3. Treating seasonality with moving averages
With seasonal data, you're going to experience many peaks and troughs in the underlying visualization. We can address this using a technique known as moving averages. Moving averages are a technique where we seek to smooth out short term fluctuations that result in peaks in our data. This helps remove some of the noisiness in our data whilst preserving the underlying shape of our data. If we look at our example here, we can clearly see in the first image we have untransformed noisy data with many sharp peaks. Once we apply a moving average, we see the peaks and troughs are now much smaller in magnitude as shown in the image at the bottom.4. Identifying seasonality with seasonal boxplots
Now whilst moving averages are useful to smooth noisy data, we can use seasonal box plots to help us segment the data into quarters for observation. Seasonal box plots provide a visual means to identify abnormal behavior which is alluded towards by the thickness of the bars for each box plot - the larger the bar, the larger the variance for the season and a potential opportunity for treatment. This can be seen in our example as we have volatility in our sales for quarter 3 and quarter 4 across the 2010 to 2014 periods.5. What's an anomaly?
Now we might examine sales over distinct time periods only to realize that a few points seem abnormally small, or large. In these cases, we might question these values - they are likely to be outliers or anomalous data points. Outliers can defined as any value that is plus or minus 3 standard deviations away from the mean, or in the case of a box plot, any value more than 1.5x below the lower quartile or 1.5x above the upper quartile. If we look at the visual here, we can clearly see that we have 1 outlier for quarter 2.6. Z-score and the normal distribution
For identifying outliers, we can also make use of Z-scores, which indicate the number of standard deviations a data point lies above or below the population mean. Simply put, if we look at the normal distribution in our image here, any score that outside of the +3 and -3 range means it is outside of the 99th percentile and can be classed as an outlier accordingly.7. Unpacking percentiles in Tableau
Now it's time for our final concept; using percentiles to help us identify anomalous data points in time series. You might not realize it but you've already been exposed to percentiles. Specifically, the median, upper and lower quartiles are all examples of percentiles in practice. We can also see this in our distribution here where 50% of the values are above a set threshold, and 50% below, giving us an idea of the spread of values. As percentiles determine where a value stands relative to other values - we have a flexible approach to identifying outliers outside of the traditional Z-scoring approach where based off our use cases, we might be more or less specific regarding our outlier classification. In the image at the bottom right, we can see how the values in orange are marked as anomalous, letting us understand what the cut-off threshold is and how many anomalous values we might have.8. Let's practice!
Now that we've covered seasonality, anomalies, Z-scores and percentiles - let's bring these concepts to life with some practice!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.