Local Outlier Factor or LOF is an algorithm implemented in DMwR package for identifying density-based local outliers, by comparing the local density of a point with that of its neighbors.
Now we will calculates the local outlier factors using the LOF algorithm using k number of neighbors:
> install.packages("DMwR")> library(DMwR)> outlier.scores <- lofactor(ozoneData, k=3)
Finally we will output the top 5 outlier by sorting the outlier score calculated above:
> outliers <- order(outlier.scores, decreasing=T)[1:5]> print(outliers)