LOF: Local Outlier Factor (LOF) algorithm

Description Usage Arguments Details Value Author(s) References Examples

Description

Function to calculate the Local Outlier Factor (LOF) as an outlier score for observations. Suggested by Breunig, M. M., Kriegel, H.-P., Ng, R. T., & Sander, J. (2000)

Usage

1
LOF(dataset, k = 5)

Arguments

dataset

The dataset for which observations have an LOF score returned

k

The number of k-nearest neighbors to compare density with. k has to be smaller than number of observations in dataset

Details

LOF computes a local density for observations with a user-given k-nearest neighbors. The density is compared to the density of the respective nearest neighbors, resulting in the local outlier factor. A kd-tree is used for kNN computation, using the kNN() function from the 'dbscan' package. The LOF function is useful for outlier detection in clustering and other multidimensional domains

Value

A vector of LOF scores for observations. The greater the LOF, the greater outlierness

Author(s)

Jacob H. Madsen

References

Breunig, M. M., Kriegel, H.-P., Ng, R. T., & Sander, J. (2000). LOF: Identifying Density-Based Local Outliers. In Int. Conf. On Management of Data. Dallas, TX. pp. 93-104. DOI: 10.1145/342009.335388

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Create dataset
X <- iris[,1:4]

# Find outliers by setting an optional k
outlier_score <- LOF(dataset=X, k=10)

# Sort and find index for most outlying observations
names(outlier_score) <- 1:nrow(X)
sort(outlier_score, decreasing = TRUE)

# Inspect the distribution of outlier scores
hist(outlier_score)

Example output

       42       107        23        16        99        14        58        61 
2.1401892 1.6923498 1.6528013 1.6070560 1.5303890 1.4684578 1.4649751 1.4608732 
       94        15        25        34        69        45       110        44 
1.4366253 1.4358094 1.3304879 1.3292011 1.2802262 1.2771899 1.2761094 1.2676266 
      118       119       132        33        19       115       135         9 
1.2640817 1.2613618 1.2609661 1.2580528 1.2538291 1.2448148 1.2289170 1.2258481 
       24       130        88       123        63        80       109        39 
1.2186105 1.2152147 1.2097245 1.1936765 1.1911372 1.1887348 1.1793638 1.1775895 
       17        43       108       126        37        85       136       101 
1.1684473 1.1647652 1.1523481 1.1513666 1.1505964 1.1465101 1.1450440 1.1422904 
      131        21       106        65        60       120       114       149 
1.1421662 1.1418438 1.1366996 1.1354693 1.1289565 1.1278678 1.1200491 1.1183161 
        6         7        32        47        51        53        82       122 
1.1171744 1.1137063 1.1052521 1.1023672 1.0987760 1.0980881 1.0899291 1.0810070 
       86        26        81       103       137        36        71        54 
1.0791422 1.0752058 1.0729744 1.0699243 1.0565329 1.0561318 1.0557874 1.0547967 
       11       142        87        77        12        67       104        73 
1.0505187 1.0475650 1.0441614 1.0426313 1.0396861 1.0388066 1.0376601 1.0359747 
      102       143       145        70        20        72        66       111 
1.0339920 1.0339920 1.0315736 1.0313942 1.0277455 1.0271560 1.0262747 1.0229170 
       49        91        27        56       112       146        78         4 
1.0224348 1.0167226 1.0147998 1.0123222 1.0116994 1.0116648 1.0115853 1.0082478 
       90        76        38        48       147       116        62        98 
1.0064326 1.0061086 1.0053093 1.0035582 1.0023075 1.0018319 1.0006954 1.0004306 
      141        22       148       105         3         5        75        59 
1.0002989 0.9993061 0.9991678 0.9982689 0.9981573 0.9976917 0.9973429 0.9971008 
      144        79       125       128         2       150        52        92 
0.9963329 0.9953478 0.9946723 0.9944197 0.9933587 0.9921152 0.9908970 0.9901783 
      121        57        74        84        97        28       138       140 
0.9895024 0.9876925 0.9871454 0.9852982 0.9852838 0.9848109 0.9848026 0.9847805 
       29       134       139       127        95        64        31        10 
0.9847763 0.9833328 0.9831949 0.9807002 0.9790946 0.9787348 0.9786418 0.9771966 
       35        50        96        83         8       113         1       117 
0.9771966 0.9767920 0.9763235 0.9761400 0.9759294 0.9756681 0.9749183 0.9743390 
       89       124        18       133        93        40        41       129 
0.9735054 0.9725387 0.9724836 0.9704360 0.9701420 0.9694070 0.9691967 0.9685807 
       13        46        55        68       100        30 
0.9681938 0.9681938 0.9627714 0.9611034 0.9597168 0.9548599 

DDoutlier documentation built on May 1, 2019, 10:20 p.m.