A short summary about Local Outlier Factor
Please find the original post here
Local Outlier Factor (LOF) is a score that tells how likely a certain data point is an outlier/anomaly.
LOF ≈ \approx ≈ 1 ⇒ no outlier
LOF > > >> >> 1 ⇒ outlier
First, I introduce a parameter k k k which is the number of neighbors the LOF calculation is considering. The LOF is a calculation that looks at the neighbors of a certain point to find out its density and compare this to the density of other points later on. Using a right number k k k isn’t straight forward. While a small k has a more local focus, i.e. looks only at nearby points, it is more erroneous when having much noise in the data. A large k k k, however, can miss local outliers.
The density of the red point to its nearest neighbors is not different from the density to the cloud in the upper right corner. However, it is probably an outlier compared to the nearest neighbors’ density.
k k k-distance
With this k k k defined, we can introduce the k-distance which is the distance of a point to its k k kth neighbor. If k was 3, the k-distance would be the distance of a point to the third closest point.
The red point’s k-distance is illustrated by the red line if k = 3 k=3 k=3.
Reachability distance
The k k k-distance is now used to calculate the reachability distance. This distance measure is simply the maximum of the distance of two points and the k-distance of the second point.
r e a c h − d i s t ( a , b ) = m a x k − d i s t a n c e ( b ) , d i s t ( a , b ) reach-dist(a,b) = max{k-distance(b), dist(a,b)} reach−dist(a,b)=maxk−distance(b),dist(a,b)
Basically, if point a is within the k k k neighbors of point b, the r e a c h − d i s t ( a , b ) reach-dist(a,b) reach−dist(a,b) will be the k k k-distance of b b b. Otherwise, it will be the real distance of a a a and b b b. This is just a “smoothing factor”. For simplicity, consider this the usual distance between two points.
The r e a c h − d i s t reach-dist reach−dist is then used to calculate still another concept — the local reachability density (lrd). To get the lrd for a point a, we will first calculate the reachability distance of a to all its k nearest neighbors and take the average of that number. The lrd is then simply the inverse of that average. Remember that we are talking about densities and, therefore, the longer the distance to the next neighbors, the sparser the area the respective point is located in. Hence, the less dense — the inverse.
l r d ( a ) = 1 / ( s u m ( r e a c h − d i s t ( a , n ) ) / k ) lrd(a) = 1/(sum(reach-dist(a,n))/k) lrd(a)=1/(sum(reach−dist(a,n))/k)
By intuition the local reachability density tells how far we have to travel from our point to reach the next point or cluster of points. The lower it is, the less dense it is, the longer we have to travel.
The lrd of the upper right point is the average reachability distance to its nearest neighbors which are points (-1, -1), (-1.5, -1.5) and (-1, -2). These neighbors, however, have other lrds as their nearest neighbors don’t include the upper right point.
The lrd of each point will then be compared to the lrd of their k neighbors. More specifically, k ratios of the lrd of each point to its neighboring points will be calculated and averaged. The LOF is basically the average ratio of the lrd of point a to the lrds to its neighboring points. If the ratio is greater than 1, the lrd of point a is on average greater than the lrd of its neighbors and, thus, from point a, we have to travel longer distances to get to the next point or cluster of points than from a’s neighbors to their next neighbors. Keep in mind, the neighbors of a point a may don’t consider a a neighbor as they have points in their reach which are way closer.
In conclusion, the LOF of a point tells the density of this point compared to the density of its neighbors. If the density of a point is much smaller than the densities of its neighbors (LOF $>>$1), the point is far from dense areas and, hence, an outlier.
Breunig, M. M., Kriegel, H. P., Ng, R. T., & Sander, J. (2000, May). LOF: identifying density-based local outliers. In ACM sigmod record (Vol. 29, No. 2, pp. 93–104). ACM.