Description Usage Arguments Details Value Author(s) References Examples
Function to identify natural neighbors and the right k-parameter for kNN graphs as suggested by Zhu, Q., Feng, Ji. & Huang, J. (2016)
1 |
dataset |
The dataset for which natural neighbors are identified along with a k-parameter |
NaN_Edges |
Choice for computing natural neighbors. Computational heavy to compute |
NAN computes the natural neighbor eigenvalue and identifies natural neighbors in a dataset. The natural neighbor eigenvalue is powerful as k-parameter for computing a k-nearest neighborhood, being suitable for outlier detection, clustering or predictive modelling. Natural neighbors are defined as two observations being mutual k-nearest neighbors. A kd-tree is used for kNN computation, using the kNN() function from the 'dbscan' package
NaN_Num |
The number of in-degrees for observations given r |
r |
Natural neighbor eigenvalue. Useful as k-parameter |
NaN_Edges |
Matrix of edges for natural neighbors |
n_NaN |
The number of natural neighbors |
Jacob H. Madsen
Zhu, Q., Feng, Ji. & Huang, J. (2016). Natural neighbor: A self-adaptive neighborhood method without parameter K. Pattern Recognition Letters. pp. 30-36. DOI: 10.1016/j.patrec.2016.05.007
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Select dataset
X <- iris[,1:4]
# Identify the right k-parameter
K <- NAN(X, NaN_Edges=FALSE)$r
# Use the k-setting in an abitrary outlier detection algorithm
outlier_score <- LOF(dataset=X, k=K)
# 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)
|
[1] "r update: 2"
[1] "r update: 3"
[1] "r update: 4"
[1] "r update: 5"
42 107 23 110 63 25 135 21
2.4799601 2.0147424 1.9591426 1.6025838 1.5581248 1.5286564 1.4801222 1.4755714
109 32 24 65 132 37 58 44
1.4551038 1.4106112 1.3764034 1.3743801 1.3667996 1.3654501 1.3593661 1.3505534
60 88 69 61 94 99 19 85
1.3493642 1.3408929 1.3370690 1.3356785 1.3291507 1.3243655 1.3025318 1.3015193
101 118 14 16 45 33 36 15
1.2963231 1.2925090 1.2837610 1.2806953 1.2621335 1.2619762 1.2614239 1.2589051
119 38 27 120 149 115 6 47
1.2505891 1.2482791 1.2467165 1.2390413 1.2386808 1.2214419 1.2166377 1.2026102
80 9 39 20 86 51 11 130
1.1740525 1.1720509 1.1720509 1.1660885 1.1514986 1.1462049 1.1439846 1.1381879
22 142 91 17 126 12 137 72
1.1310676 1.1296311 1.1266345 1.1237830 1.1234314 1.1231084 1.1158796 1.1146508
34 67 103 50 49 73 87 131
1.1123642 1.1104066 1.1094105 1.0933311 1.0896507 1.0835872 1.0793313 1.0688565
53 114 57 74 123 48 3 54
1.0686060 1.0666094 1.0654710 1.0643763 1.0609483 1.0585192 1.0575149 1.0574148
82 106 78 122 81 116 133 62
1.0571588 1.0504145 1.0483315 1.0473884 1.0469181 1.0460889 1.0431377 1.0366131
2 70 64 136 7 108 98 92
1.0322236 1.0311946 1.0300098 1.0290194 1.0280724 1.0249838 1.0247701 1.0213139
68 43 35 138 140 76 79 100
1.0212936 1.0212300 1.0210219 1.0202060 1.0165880 1.0152831 1.0120380 1.0114523
40 10 5 1 104 90 97 124
1.0100374 1.0092746 1.0088640 1.0084973 1.0082068 1.0077902 1.0077677 1.0071882
121 105 127 31 102 143 112 71
1.0069813 1.0055536 1.0040905 1.0039576 1.0038486 1.0038486 1.0035404 1.0019179
56 41 129 134 141 75 128 117
1.0012099 0.9998504 0.9985588 0.9975503 0.9957788 0.9953949 0.9925829 0.9918775
145 147 144 146 139 18 111 59
0.9913695 0.9901533 0.9886461 0.9885251 0.9847184 0.9835520 0.9784784 0.9768842
96 77 95 125 46 30 52 26
0.9755162 0.9749787 0.9737883 0.9702753 0.9686532 0.9674442 0.9640250 0.9636804
4 113 89 83 148 13 55 150
0.9604773 0.9574717 0.9547550 0.9545726 0.9449789 0.9442198 0.9398881 0.9383261
28 93 84 8 66 29
0.9314671 0.9311334 0.9280119 0.9186461 0.9120239 0.8972745
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.