Data Mining Anomaly Detection Lecture Notes for Chapter 10 Introduction to Data Mining by Tan, Steinbach, Kumar Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 1 Anomaly/Outlier Detection What are anomalies/outliers?

The set of data points that are considerably different than the remainder of the data 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 find all the data points x D having the top-k largest anomaly scores

containing mostly normal (but unlabeled) data points, and a test point x, compute the anomaly score of x with respect to D Applications: Credit card fraud detection, telecommunication fraud detection, network intrusion detection, fault detection Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 2 Causes of anomalies Data from different classes

Hawkins: differs so much from other observations Could be generated by a different mechanism Natural Variation Some people are very tall/short/ Data Measurement and Collection Errors Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004

3 Importance of Anomaly Detection 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! Tan,Steinbach, Kumar Introduction to Data Mining Sources: http://exploringdata.cqu.edu.au/ozone.html http://www.epa.gov/ozone/science/hole/size.ht ml 4/18/2004 4 Use of class labels Class labels: normal, anomaly

Supervised AD Both class labels are available Not usually considered as AD just Classification Unsupervised AD No class labels Discussed in this chapter Semi-supervised AD All training instances are known normal Generate an anomaly score for a test instance Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 5 Issues Number of attributes used to define an anomaly 2-foot tall is common, 200-pound heavy is common 2-foot and 200-pound together is not common Global versus local perspective

6.5-foot is unusually tall, but not in basketball teams. Degree/score of anomaly Identify one at a time vs multiple at once One: maskingsome anomalies hide the rest Multiple: swampingsome normal objects got lumped into the anomaly group Evaluation Efficiency Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 6 Anomaly Detection

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 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004

7 Anomaly Detection Schemes 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 Density-based Clustering-based Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 8 Graphical Approaches Boxplot (1-D), Scatter plot (2-D), Spin plot (3-D)

Limitations Time consuming Subjective Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 9 Convex Hull Method

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? Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 10 Anomaly/Outlier Detection Proximity-based (10.3) Density-based (10.4) Clustering-based (10.5) Statistical (10.1)

Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 11 Nearest-Neighbor Based Approach Approach: Compute the distance between every pair of data points There are various ways to define outliers: fewer than p neighboring points within a distance d

The top n whose distance to the kth nearest neighbor is greatest The top n whose average distance to the k nearest neighbors is greatest Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 12 Strengths and Weaknesses Simple

O(m^2) time [m data points] Sensitive to the choice of parameters Cannot handle different densities Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 13 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 14

Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 15 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 16 Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 17 Outliers in Lower Dimensional Projection 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 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 19 Example N=100, = 5, f = 1/5 = 0.2, N f2 = 4 Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 20 Anomaly/Outlier Detection Proximity-based (10.3) Density-based (10.4) Clustering-based (10.5) Statistical (10.1) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 21 Handling different densities

Example from the original paper p2 p1 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 22 Density-based: LOF approach Simplified algorithm

For each point, compute the density of its local neighborhood Inverse average distance to the k-nearest neighbors Compute local outlier factor (LOF) of a sample x as the average relative density of x with respect to its k-nearest neighbors Similar to the original paper, but reciprocal of Eq. 10.7 in the book Outliers are points with the largest LOF values Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 23 Density-based: LOF approach In the NN approach, p2 is not considered as outlier, while LOF approach find both p1 and p2 as outliers p2 p1 Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 24 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 25 Strengths and weaknesses Handles different densities O(m^2) Selecting k

Vary k, use the max outlier score Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 26 Anomaly/Outlier Detection Proximity-based (10.3) Density-based (10.4) Clustering-based (10.5) Statistical (10.1) Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 27 Clustering-based How would you use clustering algorithms for anomaly detection? Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 28

Distant small clusters Cluster the data into groups 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 Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 29 Distant Small Clusters Parameters: How small is small? How far is far? Sensitive to number of clusters (k) When k is large, more small clusters Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 30 Strength of cluster membership Outlier if not strongly belong to any cluster Prototype-based clustering Distance from centroid Density-based clustering Low density (noise points in DBSCAN)

Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 31 Prototype based clustering Strength of cluster membership Distance to centroid What if clusters have different densities Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 32 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 33 Prototype based clustering Strength of cluster membership Distance to centroid What if clusters have different densities

Ideas? Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 34 Prototype based clustering Strength of cluster membership Distance to centroid What if clusters have different densities Relative distance to centroid

Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 35 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 36 Prototype based clustering Strength of cluster membership

Distance to centroid What if clusters have different densities Relative distance to centroid Objective function such as SSE Ideas? Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 37 Prototype based clustering

Strength of cluster membership Distance to centroid What if clusters have different densities Relative distance to centroid Objective function such as SSE Improvement in SSE when an object is removed from the cluster Larger improvement means the object is less fit to the cluster Computationally expensive, why? Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 38 Impact of Outliers to Initial Clustering We cluster first But outliers affect clustering Simple approach Cluster first Remove outliers Cluster again Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 39 Impact of Outliers to Initial Clustering More sophisticated approach Special group of potential outliers dont fit well in any cluster While clustering

Add to group if an object doesnt fit well Remove from group if an object fits well Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 40 Number of clusters to use No simple answer Try different numbers Try more clusters

Clusters are smaller More cohesive Detected outliers are more likely to be real outliers However, outliers can form small clusters Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 41 Strengths and weaknesses Definition of clustering is complementary to outliers Sensitive to number of clusters Sensitive to the clustering algorithm

Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 42 Anomaly/Outlier Detection Proximity-based (10.3) Density-based (10.4) Clustering-based (10.5) Statistical (10.1) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004

43 Statistical Approaches Univariate (10.2.1) Multivariate (10.2.2) Mixture Model (10.2.3) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 44 Univariate Distribution

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) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 45 Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 46 Grubbs Test 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:

Reject H0 if: Tan,Steinbach, Kumar ( N 1) G N Introduction to Data Mining G max X X s t (2 / N , N 2 ) N 2 t (2 / N , N 2 ) 4/18/2004 47

Statistical Approaches Univariate (10.2.1) Multivariate (10.2.2) Mixture Model (10.2.3) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 48 Multivariate distribution For example, for 2D, Parameters

Mean (, (0, 0) Covariance matrix Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 49 Note the x and y axes dont have the same scale Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 50 Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 51 Mahalanobis Distance = data vector (test instance) = mean vector (center of distribution of training data) S = covariance matrix

Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 52 Statistical Approaches Univariate (10.2.1) Multivariate (10.2.2) Mixture Model (10.2.3) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004

53 Mixture Model Approach Assume the data set D contains samples from a mixture of two probability distributions: M (majority distribution) A (anomalous distribution) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 54 Mixture Model Approach

Data distribution, D = (1 ) M + A M is a probability distribution estimated from data Can be based on any modeling method (nave Bayes, maximum entropy, etc) A is initially assumed to be uniform distribution Likelihood at time t: N |At | |M t | Lt ( D ) PD ( xi ) (1 ) PM t ( xi ) 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 Tan,Steinbach, Kumar Introduction to Data Mining xi At 4/18/2004 55 Mixture Model Approach

General Algorithm: Initially, assume all the data points belong to M Let LLt(D) be the log likelihood of D at time t For each point xt that belongs to M, move it to A Let LLt+1 (D) be the new log likelihood. Compute the difference, = LLt+1(D) LLt (D) [correction from the book] If > c (some threshold), then xt is declared as an anomaly and moved permanently from M to A Tan,Steinbach, Kumar

Introduction to Data Mining 4/18/2004 56 Strengths and weaknesses Grounded in statistics Most of the tests are for a single attribute (univariate) In many cases, data distribution may not be known

For high dimensional data, it may be difficult to estimate the true distribution Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 57 Evaluation of Anomaly Detection Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 58 Evaluation of Anomaly Detection Accuracy is not appropriate for anomaly detection why? Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 59 Evaluation

Accuracy is not appropriate for anomaly detection Easy to get high accuracy--just predict normal Ideas? Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 60 Evaluation Accuracy is not appropriate for anomaly detection

Easy to get high accuracy--just predict normal We discussed these in Classification Cost matrix for different errors Precision and Recall (F measure) True-positive and false-positive rates Receiver Operating Characteristic (ROC) curve Area under the curve (AUC) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 61

Base Rate Fallacy (Axelsson, 1999) Diagnosing Disease Test is 99% accurate True-positive is 99% True-negative is 99% Bad news Test is positive Good news

1 in 10,000 has the disease Are you more likely to have the disease or not? Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 62 Base Rate Fallacy Bayes theorem:

More generally: Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 63 Total Probability =1 Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 64 Base Rate Fallacy S=Disease; P=Test Even though the test is 99% certain, your chance of having the disease is 1/100, because the population of healthy people is much larger than sick people Tan,Steinbach, Kumar Introduction to Data Mining

4/18/2004 65 Base Rate Fallacy in Intrusion Detection I: intrusive behavior, I: non-intrusive behavior A: alarm A: no alarm Detection rate (true positive rate): P(A|I) False alarm rate (false positive rate): P(A|I) Goal is to maximize both

Bayesian detection rate, P(I|A) [precision] P(I|A) Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 66 Detection Rate vs False Alarm Rate Suppose:

Then: False alarm rate becomes more dominant if P(I) is very low Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 67 Detection Rate vs False Alarm Rate

Axelsson: We need a very low false alarm rate to achieve a reasonable Bayesian detection rate Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 68