# Local Outlier Factor for Anomaly Detection

A large 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..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..Hence, the less dense — the inverse.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)..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.. More details