"Madness is rare in individuals – but in groups, parties, nations, and ages, it is the rule."
– Friedrich Nietzsche
LOF takes an opposite approach to Nietzsche's—it compares the density of a sample to the local densities of its neighbors. A sample existing in a low-density area compared to its neighbors is considered an outlier. Like any other neighbor-based algorithms, we have parameters to specify the number of neighbors to consider (n_neighbors) and the distance metric to use to find the neighbors (metric and p). By default, the Euclidean distance is used—that is, metric='minkowski' and p=2. You can refer to Chapter 5, Image Processing with Nearest Neighbors, for more information about the available distance metrics. Here is how we useLocalOutlierFactor for outlier detection, using 50 neighbors and its default distance metric:
from sklearn.neighbors import LocalOutlierFactor...