Anomaly detection - Anomaly detection using the multivariate Gaussian distribution

Let's develop a different anomaly detection algorithm based on multivariate Gaussian distribution.

Parameters fitting

Figure-1

The upper part of figure-1 is a recap for definition of multivariate Gaussian distribution. Also it shows a range of different distributions as verying \mu and \Sigma. The lower part shows how to fit the parameters. If I have a set of examples

{x^{(1)}, x^{(2)},...,x^{(m)}}, x\in \mathbb{R}^{n}

Then you set \mu as the average of all examples. And set \Sigma=\frac{1}{m}\sum _{i=1}^{m}(x^{(i)}-\mu )(x^{(i)}-\mu )^{T}

So given the data set, we can estimate \mu and \Sigma. And get definition of p(x; \mu , \Sigma )

Multivariate Gaussian algorithm

Figure-2

Figure-2 shows the steps of anomaly detection with multivariate Gaussian algorithm.

  1. First, we take our training set and fit the model p(x) by setting \mu and \Sigma as described in section "Parameters fitting".
  2. Next, when you're given a new test example x, the green cross, we need compute p(x) using the formula for the multivariate Gaussian distribution.
  3. Then, if p(x)< \epsilon, we flag it as an anomaly; otherwise, we don't flag it as an anomaly.

It turns out, if we were to fit a multivariate Gaussain distribution to this data set (red crosses), you end up with a distribution that places lots of probability in the central regions, slightly less probability in the outer regions. And very low probability at the green cross point. And the green cross example will be correctly flaged as an anomaly.

Relationship to original model

Figure-3

The original model corresponds to multivariate Gaussian where the contours of the Gaussian are always axes aligned.

Mathematically, it turns out that the original model

p(x)=p(x_{1}; \mu _{1}, \sigma _{1}^{2}) \times p(x_{2}; \mu _{2}, \sigma _{2}^{2}) \times...\times p(x_{n}; \mu _{n}, \sigma _{n}^{2})

is actually the same as a multivariate Gaussian distribution but with a constraint that everything on the off diagonal of \Sigma is 0:

\Sigma =\begin{bmatrix} \sigma _{1}^{2} & 0 & 0 & 0\\ 0 & \sigma _{2}^{2} & 0 & 0\\ 0 & 0 & ... & 0\\ 0 & 0 & 0 & \sigma _{n}^{2}\\ \end{bmatrix}

if you plug \sigma _{1}^{2}, \sigma _{2}^{2}...\sigma _{n}^{2} of original model into \Sigma, then the two models are actually identical.

So the original model is actually a special case of this multivariate Gaussian model.

Which one to use?

Figure-4

When would you use each of these two models? In general, the original model is probably used somewhat more often; whereas the multivariate Gaussian distribution is used somewhat less but it has the advantage of being able to capture correlations between features. Above figure-4 shows the scenarios.

If the sigma is singular

If you're fitting with multivariate Gaussian and find that \Sigma is non-invertible, then there are usually two cases for this:

  1. Failed to satisfy m> n condition
  2. You have redundant features which means that features that are linearly dependent. For example, you had two copies of the same feature; or maybe you have some feature like x_{3}=x_{4}+x_{5}.

<end>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值