2
$\begingroup$

I have a set of signals on which I have to implement an anomaly detection algorithm. The data is split among a reference period (i.e. last 3 months) and a test period (i.e. last week). I've already built an autoencoder model which is trained (and validated) with the data on the reference period. Then the test period is scored.

I would like to know how to make an "indicator" (single number) of how the two distribution look alike, or how "anomalous" is the second distribution compared to the first one.

I have calculated the reconstruction error in the training set and in the test set for each point (calculated as the squared distance between the original and the reconstructed point), as well as the MSE in both sets of course.

Things I've tried:

  • get the ratio of MSEs (>1 means the second distribution is "anomalous", but how much? what threshold can I set?)
  • get the 95% percentile of both the error sets and get the ratio
  • count the points beyond the 95% percentile of both the error sets and get the ratio

but none of these seems a good stable indicator.

What would you recommend?

$\endgroup$

1 Answer 1

6
$\begingroup$

I had some observations in a very similar setting:

  • The error distribution on the training data is misleading since your training error distribution is not identical to test error distribution, due to inevitable over-fitting. Then, comparing training error distribution with future data is unjust. A better approach is to keep a portion of the training set out of the training session and using it exclusively for revealing the error distribution. You should note that, this portion of the data should be anomaly-free.

  • How the two distribution look alike might not be a good idea in an anomaly detection setting since we are generally interested in point anomalies, e.g. anomalies of single samples. Thus, it is better to benchmark this single sample's MSE against a your error distribution, rather than comparing distributions.

  • You can determine your threshold value through either a supervised or an unsupervised scheme. Supervised approach is simple. You can tune your threshold value as a hyper-parameter based on its success at detecting labelled anomalies. The key point here is not to use test data for this. Hyper-parameter tuning on the test data will lead to over-fitting. So, you should crop some validation data. If you do not possess any labelled data, then you should consult some statistical measures at the risk of losing some detection capability. You can simply set a threshold based on: 95% percentile or $Median+1.5*IQR$ (IQR: Interquartile range). You can also use z-scores, but do not forget that z-score's connection to the the percentiles depends on the shape of the distribution. In case of a Gaussian distribution, you can safely apply z-scores with a threshold of $z=3.5$. As another option, you can give a chance to Chebyshev’s Theorem (link) which applies to all kinds of distributions. It outputs an interval where $k\%$ of the data is guaranteed to sit on.

$\endgroup$
3
  • $\begingroup$ Thanks a lot for your ideas, getting the error distribution from a subset of the training set excluded from the training is a great idea. About the z-score, I see that my error distribution usually seems to have a Chi-square shape (clearly always positive, with a high bell shape between 0 and 1, and a long right tail). How would you calculate the z-score in this case? $\endgroup$
    – edoedoedo
    Commented Sep 16, 2019 at 14:58
  • $\begingroup$ I tried the Chebyshev's Theorem setting the "normal interval" in [mu-2*sigma, mu+2*sigma] but it seems wrong due to the shape of the error distribution... Since the tail is right only, I would expect the "normal interval" to be like [0,K]. $\endgroup$
    – edoedoedo
    Commented Sep 17, 2019 at 8:28
  • $\begingroup$ Sorry for my late response! For your first question: You can consult to 95% or 1.5*IQR thresholds. If you have some anomaly-labelled data, it will be most successful if you tune the threshold. For the Chebyshev's part: It provides an interval where k% of your data sit on. It does not need to be on the support of your distribution (a little bit unintuitive). Generally, we are after higher MSE values (reconstruction fails), and onlythe upper bound will be sufficient. Yet, mu+2*sigma might be a loose bound since it will only cover 75% of your data. You can try a sharper value, e.g. 4. $\endgroup$
    – Monotros
    Commented Sep 17, 2019 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.