15. Anomaly detection

Anomaly detection

Problem motivation

Gaussian distribution

Gaussian distribution: Say x\in R. If x is a distributed Gassian with mean \mu, variance \sigma^2

x\sim N(\mu,\sigma^2)

P(x;\mu,\sigma^2) = \frac{1}{\sqrt{2\pi}\sigma}\exp^{(-\frac{(x-\mu)^2}{2\sigma^2})}

Parameter estimation:

\mu = \frac{1}{m}\sum\limits_{i=1}^mx^{(i)}
\sigma^2 = \frac{1}{m}\sum\limits_{i=1}^m(x^{(i)}-\mu)^2

m = m-1, whether use m or m-1 make very little difference.

Algorithm

Density estimation

\begin{aligned} P(x) & = P(x_1;\mu_1,\sigma_1^2)P(x_2;\mu_2,\sigma_2^2)...P(x_n;\mu_n,\sigma_n^2) \\ & =\prod_{j=1}^nP(x_j;\mu_j,\sigma_j^2) \end{aligned}

Anomaly detection algorithm

  1. Choose features x_i that you think might be indicative of anomalous examples.
  2. Fit parameters \mu_1,...,\mu_n,\sigma_1^2,...,\sigma_n^2
  3. Given new example x, compute p(x):
    \begin{aligned} P(x) & = P(x_1;\mu_1,\sigma_1^2)P(x_2;\mu_2,\sigma_2^2)...P(x_n;\mu_n,\sigma_n^2) \\ & =\prod_{j=1}^nP(x_j;\mu_j,\sigma_j^2) \end{aligned}
    Anomaly if p\le \epsilon

Developing and evaluating an anomaly detection system

Whem developing a learning algorithm (choosing features, etc.), making decisions is much easier if we have a way of evaluating our learning algorithm.

Assume we have some labeled data, of anomalous and non-anomalous examples.

  • Training set (normal examples)
  • cross validiation set (labeled examples)
  • test set (labeled examples)

Can also use cross validation set to choose parameter \epsilon

Anomaly detection vs. supervised learning

Anomaly detection Supervised learning
Very small number of positive examples; Large number of negative examples Large number of positive examples and negative examples
Hard for any algorithm to learn from positive examples what the anomalies look like; future anomalies may look nothing like any of the anomalous examples we've seen so far. Enough positive examples for algorithm to get a sense of what positive examples are like, future positive examples likely to be similar to ones in training set.

Choosing what features to use

Non-gaussian features: make your data more like Gaussian.

Error analysis for anomaly detection

  • Most common problem: p(x) is comparable (say, both large) for normal and anomalous examples.
    Create some new features.
  • Choose featrues that might take on unusually large or small values in the event of an anomaly.

Multivariate Gaussian distribution

  • x\in R^n. Don't model p(x_1),p(x_2),..., etc. separately.
  • Model p(x) all in one go.
  • Parameters: \mu\in R^n, \Sigma\in R^{n\times n}

p(x;\mu,\sigma) = \frac{1}{(2\pi)^{n/2}\det(\Sigma)^{1/2}}\exp(-\frac{1}{2}(x-\mu)^T\Sigma^{-1}(x-\mu))

there are some pics that show the multivariate gaussian look like in the video.

Anomaly detection using the multivariate Gaussian distribution

p(x;\mu,\sigma) = \frac{1}{(2\pi)^{n/2}\det(\Sigma)^{1/2}}\exp(-\frac{1}{2}(x-\mu)^T\Sigma^{-1}(x-\mu))

\begin{aligned} \mu & = \frac{1}{m}\sum_{i=1}^mx^{(i)} \\ \Sigma & = \frac{1}{m}\sum_{i=1}^m(x^{(i)l}-\mu)(x^{(i)}-\mu)^T \end{aligned}

Original model vs. Multivariate Gaussian

original model:

  • manually create features to capture anomalies where x_1,x_2 take unusual combinations of values.
  • computationally cheaper
  • ok even if m is small

multivariate Gaussian:

  • automatically captures correlations between features
  • computationally more expensive
  • must have m\ge n, or else \Sigma is non-invertible
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市崎逃,隨后出現(xiàn)的幾起案子糙捺,更是在濱河造成了極大的恐慌弧关,老刑警劉巖赊堪,帶你破解...
    沈念sama閱讀 222,590評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件网梢,死亡現(xiàn)場離奇詭異,居然都是意外死亡嚣伐,警方通過查閱死者的電腦和手機糖赔,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,157評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來轩端,“玉大人放典,你說我怎么就攤上這事』穑” “怎么了奋构?”我有些...
    開封第一講書人閱讀 169,301評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長拱层。 經(jīng)常有香客問我弥臼,道長,這世上最難降的妖魔是什么根灯? 我笑而不...
    開封第一講書人閱讀 60,078評論 1 300
  • 正文 為了忘掉前任径缅,我火速辦了婚禮,結果婚禮上烙肺,老公的妹妹穿的比我還像新娘纳猪。我一直安慰自己,他們只是感情好茬高,可當我...
    茶點故事閱讀 69,082評論 6 398
  • 文/花漫 我一把揭開白布兆旬。 她就那樣靜靜地躺著,像睡著了一般怎栽。 火紅的嫁衣襯著肌膚如雪丽猬。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,682評論 1 312
  • 那天熏瞄,我揣著相機與錄音脚祟,去河邊找鬼。 笑死强饮,一個胖子當著我的面吹牛由桌,可吹牛的內容都是我干的。 我是一名探鬼主播邮丰,決...
    沈念sama閱讀 41,155評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼行您,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了剪廉?” 一聲冷哼從身側響起娃循,我...
    開封第一講書人閱讀 40,098評論 0 277
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎斗蒋,沒想到半個月后捌斧,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體笛质,經(jīng)...
    沈念sama閱讀 46,638評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,701評論 3 342
  • 正文 我和宋清朗相戀三年捞蚂,在試婚紗的時候發(fā)現(xiàn)自己被綠了妇押。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,852評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡姓迅,死狀恐怖敲霍,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情丁存,我是刑警寧澤色冀,帶...
    沈念sama閱讀 36,520評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站柱嫌,受9級特大地震影響,放射性物質發(fā)生泄漏屯换。R本人自食惡果不足惜编丘,卻給世界環(huán)境...
    茶點故事閱讀 42,181評論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望彤悔。 院中可真熱鬧嘉抓,春花似錦、人聲如沸晕窑。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,674評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽杨赤。三九已至敞斋,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間疾牲,已是汗流浹背植捎。 一陣腳步聲響...
    開封第一講書人閱讀 33,788評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留阳柔,地道東北人焰枢。 一個月前我還...
    沈念sama閱讀 49,279評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像舌剂,于是被迫代替她去往敵國和親济锄。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,851評論 2 361