Lecture 24: Anomaly Detection
What are anomalies/outliers?
– The set of data points that are considerably different
than the remainder of the data
Applications:
– Credit card fraud detection, telecommunication fraud
detection, network intrusion detection, fault detection
2
Ozone Depletion History
In 1985 three researchers (Farman,
Gardinar and Shanklin) were
puzzled by data gathered by the
British Antarctic Survey showing that
ozone levels for Antarctica had
dropped 10% below normal levels
Why did the Nimbus 7 satellite,
which had instruments aboard for
recording ozone levels, not record
similarly low ozone concentrations?
The ozone concentrations recorded
by the satellite were so low they
were being treated as outliers by a
computer program and discarded!
Variants of Anomaly/Outlier Detection Problems
– Given a database D, find all the data points x ∈ D with
anomaly scores greater than some threshold t
– Given a database D, find all the data points x ∈ D
having the top-n largest anomaly scores f(x)
– Given a database D, containing mostly normal (but
unlabeled) data points, and a test point x, compute the
anomaly score of x with respect to D
4
Challenges
– How many outliers are there in the data?
– Method is unsupervised
Validation can be quite challenging (just like for clustering)
– Finding needle in a haystack
Working assumption:
– There are considerably more “normal” observations
than “abnormal” observations (outliers/anomalies) in
the data
General Steps
– Build a profile of the “normal” behavior
Profile can be patterns or summary statistics for the overall population
– Use the “normal” profile to detect anomalies
Anomalies are observations whose characteristics
differ significantly from the normal profile
Types of anomaly detection
schemes
– Graphical & Statistical-based
– Distance-based
6
Boxplot (1-D), Scatter plot (2-D), Spin plot (3-D)
Limitations
– Time consuming
– Subjective
!" #
Extreme points are assumed to be outliers
Use convex hull method to detect extreme values
What if the outlier occurs in the middle of the
data?
8
Assume a parametric model describing the
distribution of the data (e.g., normal distribution)
Apply a statistical test that depends on
– Data distribution
– Parameter of distribution (e.g., mean, variance)
– Number of expected outliers (confidence limit)
$$ %&
Detect outliers in univariate data
Assume data comes from normal distribution
Detects one outlier at a time, remove the outlier,
and repeat
– H0: There is no outlier in data
– HA: There is at least one outlier
Grubbs’ test statistic: max X − X
G=
s
Reject H0 if: t (2α / N , N −2 )
( N − 1)
G>
N N − 2 + t (2α / N , N − 2 )
10
'$ #( )* #
Assume the data set D contains samples from a
mixture of two probability distributions:
– M (majority distribution)
– A (anomalous distribution)
General Approach:
– Initially, assume all the data points belong to M
– Let Lt(D) be the log likelihood of D at time t
– For each point xt that belongs to M, move it to A
Let Lt+1 (D) be the new log likelihood.
Compute the difference, ∆ = Lt(D) – Lt+1 (D)
If ∆ > c (some threshold), then xt is declared as an anomaly
and moved permanently from M to A
11
'$ #( )* #
Data distribution, D = (1 – λ) M + λ A
M is a probability distribution estimated from data
– Can be based on any modeling method (naïve Bayes,
maximum entropy, etc)
A is initially assumed to be uniform distribution
Likelihood at time t:
N
Lt ( D ) = ∏ PD ( xi ) = (1 − λ )|M t | ∏ PM t ( xi ) λ| At | ∏ PAt ( xi )
i =1 xi ∈M t xi ∈At
LLt ( D ) = M t log(1 − λ ) + log PM t ( xi ) + At log λ + log PAt ( xi )
xi ∈M t xi ∈At
12
)
Most of the tests are for a single attribute
In many cases, data distribution may not be
known
For high dimensional data, it may be difficult to
estimate the true distribution
13
'$ #
Data is represented as a vector of features
Three major approaches
– Nearest-neighbor based
– Density based
– Clustering based
14
+ '+ $ , #
Approach:
– Compute the distance between every pair of data
points
– There are various ways to define outliers:
Data points for which there are fewer than p neighboring
points within a distance D
The top n data points whose distance to the kth nearest
neighbor is greatest
The top n data points whose average distance to the k
nearest neighbors is greatest
15
)- . /
In high-dimensional space, data is sparse and
notion of proximity becomes meaningless
– Every point is an almost equally good outlier from the
perspective of proximity-based definitions
Lower-dimensional projection methods
– A point is an outlier if in some lower dimensional
projection, it is present in a local region of abnormally
low density
16
)- . /
Divide each attribute into φ equal-depth intervals
– Each interval contains a fraction f = 1/φ of the records
Consider a k-dimensional cube created by
picking grid ranges from k different dimensions
– If attributes are independent, we expect region to
contain a fraction fk of the records
– If there are N points, we can measure sparsity of a
cube D as:
– Negative sparsity indicates cube contains smaller
number of points than expected
17
N=100, φ = 5, f = 1/5 = 0.2, N × f2 = 4
18
'$ #)0
For each point, compute the density of its local neighborhood
Compute local outlier factor (LOF) of a sample p as the
average of the ratios of the density of sample p and the
density of its nearest neighbors
Outliers are points with largest LOF value
! "
# $
p2
× p1
×
19
', #
Basic idea:
– Cluster the data into
groups of different density
– Choose points in small
cluster as candidate
outliers
– Compute the distance
between candidate points
and non-candidate
clusters.
If candidate points are far
from all other non-candidate
points, they are outliers
20