Anomaly Detection Shiny App
Contributed by Kyle Szela. He is currently in the NYC Data Science Academy 12 week full time Data Science Bootcamp program taking place betweenย April 11th to July 1st, 2016. This post is based on his second class project - Shiny App (due on the 4th week of theย program).
Introduction:
My initial idea for a shiny app was to take ECG data (the recordings of electrical and muscular activity of the heart) and apply anomaly detection with seasonal periodicity taken into account. ย Unfortunately, the mutation of the dataset into an acceptable time series proved extremely difficult. ย So difficult, that I wanted to make it easier for others to be able to perform this time series anomaly detection easily. ย The end result is an app that will take in a dataset and attempt to perform the associated anomaly detection algorithm despite time series data that is not easily cast to a R compatible format.
Uploading and Viewing the Dataset:
The first tab, shown below, allows for the uploading of a dataset into the app. ย It allows the user to specify the inclusion of the header, the delimiter, and the type of quotation of the .csv file. ย The user simply clicks the "Choose File" button, finds their csv file, and uploads it.
Once the dataset is uploaded, the app will attempt to cast the first column into a timestamp format. ย If it is not able to do this, it will cast the sample number into a time series, instead, and will display the old data as a third column. ย The corresponding time series graph will be presented in the "Data Chart" section, while the csv data will be presented in table format in the "Data" section.
Performing Filtering:
The next tab allows the user to filter his or her data with either a Butterworth or a Type-II Chiebyshev filter. ย The idea behind these filters is that they allow the user to partially select the different anomalies to detect, as well as remove noise from the dataset and aid in the visualization of the time series data. ย Choosing not to filter the data will not remove the ability to perform the time series anomaly detection. ย I've found that the Butterworth filter does a pretty great job of smoothing out the dataset.
Anomaly Detection:
The last tab allows the user to detect anomalous points in their dataset. ย In the "Settings" section, there are a few different options for the user to choose. ย The "Max % of Anomalies" refers to the maximum number of anomalous points to be found, as a percentage of the total data set. ย The "alpha" refers to the statistical significance required for each point to be considered an anomaly. ย Lastly, the "Direction" radio buttons allow the user to choose if they would like to find only the positive, negative, or both directional anomalies.
Once the user has selected their settings, and the "Filter" button has been pressed, a graph is displayed in the "Data Chart" section that affords the ability to pinpoint the individual anomalous points in the time series. ย Additionally, these points will be presented in table format in the "Data" section, and are available for download.