# Anomaly detection thresholds issue

I'm working on an anomaly detection development in Python.
More in details, I need to analysed timeseries in order to check if anomalies are present.
An anomalous value is typically a peak, so a value very high or very low compared to other values.

The main idea is to predict timeseries values and, using thresholds, detect anomalies.

Thresholds are calculated using the error, that is the real values minus the predicted ones.
Then, mean and standard deviation of the error are performed.

The upper threshold is equals to mean + (5 * standard deviation).
The lower threshold is equals to mean - (5 * standard deviation).

If the error exceeds thresholds is marked as anomalous.

What doesn't work with this approach is that if I have more than one anomalous value in a day, they are not detected. This because error, mean and standard deviation are too much influenced by anomalous values.

How can i fix this problem? Is there another method that i can use to identify thresholds without this issue?

Thank you

• Does your data vary significantly from day to day? Oct 29, 2019 at 22:24
• no, data are quite similar Oct 30, 2019 at 8:00
• In the equation: The upper threshold is equals to mean + (5 * standard deviation) are mean and standard deviation of the one day sample or is it of a much larger period? Oct 30, 2019 at 19:40

You will probably have to change your critical value to something other than 5 to get the same kind of coverage. According to Wikipedia, you'll want the new critical value to be $$5\sqrt{\frac{\pi}{2}}$$ if your data are iid Gaussian.