Algorithm Search⌘K

Problemintro

Anomaly detection

Also called outlier detection, novelty detection.

Given data that come mostly from normal behavior, learn a score that is high on points unlike that behavior, and flag the points whose score passes a threshold.

Anomaly detection is the problem of finding the points of a data set, or the new points of a stream, that do not look like the normal behavior that produced most of the data. A method for it learns a score that is high on unusual points, and a threshold turns the score into a yes or no answer, so the result has the two errors of a statistical test: false alarms and misses. In security it is the basis of anomaly-based intrusion detection, which Denning (1987) proposed on the hypothesis that an attack shows as abnormal use. The other names are outlier detection, when the training set itself is scored, and novelty detection, when a clean training set is given and new points are scored.

In plain words

You have a lot of records of normal activity: logins, network connections, program runs. You want a machine to point at the records that are strange.

Nobody tells the machine what an attack looks like. It only sees mostly normal data. So it learns what normal looks like and gives each record a number: how far the record is from normal. A large number means strange. You then pick a cut-off. Records above the cut-off raise an alarm.

The cut-off is a trade. A low cut-off catches more attacks but raises more false alarms. A high cut-off is quiet but misses attacks. Because real attacks are rare, even a small rate of false alarms can bury the real ones.

Definition

Let X\mathcal{X} be the space of the data: Rd\mathbb{R}^d for numeric features, or a set of strings for payloads and traces. Normal data come from a distribution PP on X\mathcal{X}, and anomalies from an unknown distribution QQ.

Input. A training sample x1,…,xn∈Xx_1, \ldots, x_n \in \mathcal{X}. In novelty detection all of it comes from PP. In outlier detection it comes from the mixture (1−π)P+πQ(1 - \pi) P + \pi Q with an unknown small π≥0\pi \ge 0.

Output. A score function s:X→Rs : \mathcal{X} \to \mathbb{R}, where a larger score means more anomalous, and a threshold tt. The detector flags xx when s(x)>ts(x) > t. The flag set is At={x:s(x)>t}A_t = \{x : s(x) > t\}.

The two errors. The false alarm rate is FAR(t)=P(At)\mathrm{FAR}(t) = P(A_t) and the detection rate is DR(t)=Q(At)\mathrm{DR}(t) = Q(A_t). A good method has a small FAR\mathrm{FAR} and a large DR\mathrm{DR} over a range of thresholds. Because QQ is not known, the methods are judged on test data with labels, by the curve of (FAR(t),DR(t))(\mathrm{FAR}(t), \mathrm{DR}(t)) over tt (the ROC curve, see ROC AUC) or by the precision at a fixed alarm budget.

The level set form. For a level ν∈(0,1)\nu \in (0, 1), find a set C⊆XC \subseteq \mathcal{X} of the smallest volume with P(C)≥1−νP(C) \ge 1 - \nu, and flag the points outside CC. When PP has a density pp with no flat parts, the answer is the density level set {x:p(x)≥τ}\{x : p(x) \ge \tau\} for the τ\tau that gives mass 1−ν1 - \nu. This is the problem that the one-class SVM solves approximately (Scholkopf et al. 2001).

Variants

  • Outlier detection (unsupervised, transductive). Score the training points themselves and report the top mm of them, or all with a score above tt. k-nearest-neighbor outlier detection and the local outlier factor are stated in this form.
  • Novelty detection (semi-supervised). Train on data that hold only normal points, then score new points. Most intrusion detectors work this way, with a training period that is assumed to be free of attacks.
  • Supervised detection. Labels of both kinds exist. This is classification with very unequal classes, and the precision and recall of the rare class are the right measures.
  • Point, contextual and collective anomalies. Chandola et al. separate a single strange point, a point that is strange only in its context (a high load at night), and a group of points that is strange only together (a sequence of system calls). System call sequence detection is of the third kind.
  • Streams. The points arrive one at a time and the model of normal must change with the data, without learning the attacks into the model.

Examples

Six points on a line. Take the data 1.0,1.5,2.0,2.5,3.0,9.01.0, 1.5, 2.0, 2.5, 3.0, 9.0 and the score "distance to the 2nd nearest other point". The scores are 1.0,0.5,0.5,0.5,1.0,6.51.0, 0.5, 0.5, 0.5, 1.0, 6.5. With the threshold t=2t = 2, only 9.09.0 is flagged. With t=0.75t = 0.75, the two end points of the cluster are flagged too: two false alarms.

The best possible errors on a small space. Let X={a,b,c}\mathcal{X} = \{a, b, c\} with P=(0.5,0.4,0.1)P = (0.5, 0.4, 0.1) and Q=(0.1,0.2,0.7)Q = (0.1, 0.2, 0.7). The likelihood ratios Q/PQ/P are 0.20.2, 0.50.5 and 77. At a false alarm rate of at most 0.10.1, the best flag set is {c}\{c\}, with FAR=0.1\mathrm{FAR} = 0.1 and DR=0.7\mathrm{DR} = 0.7. The total variation distance is TV(P,Q)=12(0.4+0.2+0.6)=0.6\mathrm{TV}(P, Q) = \frac12(0.4 + 0.2 + 0.6) = 0.6, so no detector has FAR+(1−DR)\mathrm{FAR} + (1 - \mathrm{DR}) below 0.40.4, and {c}\{c\} reaches it: 0.1+0.3=0.40.1 + 0.3 = 0.4.

Rare attacks. With anomalies at a base rate of 2×10−52 \times 10^{-5}, a detection rate of 0.70.7 and a false alarm rate of 10−510^{-5}, Bayes' rule gives P(anomaly∣alarm)=0.58334P(\text{anomaly} \mid \text{alarm}) = 0.58334. The base-rate fallacy page works through this example of Axelsson.

Known algorithms

AlgorithmTimeSpacePropertiesCode
Isolation forestO(t s d log s + n t log s) worstO(t s) extrarandomizednot exactofflinerecursive1 language
k-nearest-neighbor outlier detectionO(n^2 (d + log k) + n log m) worstO(k + m) extradeterministicexactofflineiterative1 language
Local outlier factorO(n^2 (d + log n)) worstO(n^2) extradeterministicexactofflineiterative1 language
One-class support vector machineO(n^2 d + r n) worstO(n^2) extradeterministicnot exactofflineiterative1 language
Payload anomaly detectionO(s + 256 n) worstO(256 b) extradeterministicexactonlineiterative1 language
PCA subspace method for traffic anomaliesO(t m^2 + w m^3) worstO(t m + m^2) extradeterministicnot exactofflineiterative1 language
Support vector data descriptionO(n^2 d + r n) worstO(n^2) extradeterministicnot exactofflineiterative1 language
System call sequence anomaly detectionO(k s) worstO(k u) extradeterministicexactonlineiterative1 language

Bounds

The best test when both distributions are known. Suppose PP and QQ have densities pp and qq. By the Neyman-Pearson lemma, for each false alarm level α\alpha, the test that flags xx when q(x)/p(x)>λq(x)/p(x) > \lambda (with randomization at the boundary) has the largest detection rate among all tests with FAR≤α\mathrm{FAR} \le \alpha. So the best score is the likelihood ratio. When QQ is the uniform distribution on a bounded set that holds the data, qq is constant, and the best test flags the points where p(x)p(x) is small. This is why "low density" is the default meaning of "anomalous", and why the level set form above is the natural goal when nothing is known about the attacks.

No test beats the overlap. For each flag set AA,

FAR+(1−DR)=P(A)+1−Q(A)≥1−sup⁡B(Q(B)−P(B))=1−TV(P,Q),\mathrm{FAR} + (1 - \mathrm{DR}) = P(A) + 1 - Q(A) \ge 1 - \sup_{B} \big(Q(B) - P(B)\big) = 1 - \mathrm{TV}(P, Q),

with equality for A={x:q(x)>p(x)}A = \{x : q(x) > p(x)\}. So when the anomalies look like normal data, as a careful attacker tries to make them, no score separates them. This is a theorem about the two distributions, not about a method.

Cost. The cost of each method is in its own model. Methods on numeric data are stated in the real-RAM model, and the string methods in the word-RAM model. Scoring every point of a sample by its nearest neighbors needs all pairwise distances in the worst case, Θ(n2d)\Theta(n^2 d) time by brute force. Index structures such as the k-d tree help in low dimension and lose their advantage as dd grows (the curse of dimensionality).

Reductions

  • To density estimation. An estimate p^\hat p gives the score s(x)=−log⁡p^(x)s(x) = -\log \hat p(x). The reduction is exact for the level set form when p^=p\hat p = p, and it is only as good as p^\hat p, which is hard to estimate in high dimension.
  • To binary classification. Steinwart, Hush and Scovel (2005) reduce density level detection to the classification of the data against samples of a known reference distribution, such as the uniform one, with a weighted loss. A classifier with a small weighted error then gives a set close to the level set.
  • To hypothesis testing. For each point, the question "is xx drawn from PP?" is a test of a simple null against an unknown alternative. A threshold on a score at the (1−α)(1 - \alpha) quantile of the scores on normal data gives a false alarm rate close to α\alpha, when the normal data of the test come from the same PP.

Applications

  • Intrusion detection. Profiles of normal use of hosts and networks, in the line of Denning's model: system call sequences, payload byte distributions and traffic volumes on network links. Sommer and Paxson (2010) explain why this works less well than in other fields: the cost of a false alarm is high, normal traffic changes all the time, an alarm is hard to explain to an operator, and the attacks are rare and chosen by an adversary.
  • Fraud and fault detection. Unusual card transactions, unusual sensor readings in a machine, unusual readings in medical monitoring.
  • Data quality. Unusual records in a data set before analysis. In genomics, a model trained on known good variant calls can score new calls; see variant quality score recalibration.

A detector that runs against an adversary must state the threat model. An attacker who knows the score can shape the attack to look normal (an evasion attack), or can put attack data into the training period so that the model learns it as normal (data poisoning). The overlap bound above says what the best detector can do when the attacker succeeds in making QQ close to PP.

References

  1. Varun Chandola, Arindam Banerjee and Vipin Kumar, Anomaly detection, a survey, ACM Computing Surveys 41(3), article 15, 2009, Section 2 (the nature of the input, the point, contextual and collective anomalies, the supervised, semi-supervised and unsupervised settings, scores against labels), Section 3 (applications, with intrusion detection), Sections 4 to 9 (the families of methods)
  2. Bernhard Scholkopf, John C. Platt, John Shawe-Taylor, Alex J. Smola and Robert C. Williamson, Estimating the support of a high-dimensional distribution, Neural Computation 13(7), 2001, Sections 1 and 2 (the support and quantile estimation problem, the minimum volume set of mass 1 - nu)
  3. Ingo Steinwart, Don Hush and Clint Scovel, A classification framework for anomaly detection, Journal of Machine Learning Research 6, 2005, the reduction of density level detection to binary classification of the data against a known reference measure
  4. Robin Sommer and Vern Paxson, Outside the closed world, on using machine learning for network intrusion detection, IEEE Symposium on Security and Privacy 2010, pages 305 to 316, the section on the challenges of machine learning for intrusion detection (outlier detection, the high cost of errors, the semantic gap, the diversity of traffic, the difficulty of evaluation) and the section of recommendations
  5. Dorothy E. Denning, An intrusion-detection model, IEEE Transactions on Software Engineering 13(2), 1987, pages 222 to 232, the hypothesis that misuse shows as abnormal use, and the profiles of normal use

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml