Detecting point anomalies using Grubb's test
Grubb's test (also known as the maximum normed residual test) is used to detect anomalies in a univariate dataset (which means there is only one variable per data instance) under the assumption that the data is generated by a Gaussian distribution. For each test instance , its score is computed as follows:
Where is the average of the data in the instances and is the standard deviation of the data points.
The following functions determine the scores of each element in the list:
A data instance is declared to be anomalous if it fulfills the following condition:
Here, is the number of elements in the collection and is the threshold used to declare an instance to be anomalous or normal.
The following function finds the elements where the score indicates that the element might be anomalous. The xs
parameter denotes the entire collection and t denotes the value of .
The following code shows you how to use these functions to find anomalous data instances...