Skip to contents

This function computes an ensemble score using the greedy algorithm in the paper titled Evaluation of Outlier Rankings and Outlier Scores by Schubert et al (2012) <doi:10.1137/1.9781611972825.90>. The greedy ensemble is detailed in Section 4.3.

Usage

greedy_ensemble(X, kk = 5)

Arguments

X

The input data containing the outlier scores in a dataframe, matrix or tibble format. Rows contain observations and columns contain outlier detection methods.

kk

The number of estimated outliers.

Value

A list with the components:

scores

The ensemble scores.

methods

The methods that are chosen for the ensemble.

chosen

The chosen subset of original anomaly scores.

Examples

set.seed(123)
if (requireNamespace("dbscan", quietly = TRUE)){
X <- data.frame(x1 = rnorm(200), x2 = rnorm(200))
X[199, ] <- c(4, 4)
X[200, ] <- c(-3, 5)
# Using different parameters of lof for anomaly detection
y1 <- dbscan::lof(X, minPts = 10)
y2 <- dbscan::lof(X, minPts = 20)
knnobj <- dbscan::kNN(X, k = 20)
# Using different KNN distances as anomaly scores
y3 <- knnobj$dist[ ,10]
y4 <- knnobj$dist[ ,20]
# Dense points are less anomalous. Hence 1 - pointdensity is used.
y5 <- 1 - dbscan::pointdensity(X, eps = 0.8, type = "gaussian")
y6 <- 1 - dbscan::pointdensity(X, eps = 0.5, type = "gaussian")
Y <- cbind.data.frame(y1, y2, y3, y4, y5, y6)
ens <- greedy_ensemble(Y, kk=5)
ens$scores
}
#>   [1] 0.7749993012 0.4321599887 0.5845229698 0.1135792510 0.0405051381
#>   [6] 0.6680514135 0.2223657022 0.4965478184 0.6010439417 0.0667362881
#>  [11] 0.4265269819 0.0779196815 0.4636297538 0.0654657170 0.3314708968
#>  [16] 0.8692956823 0.1225212510 0.7959482599 0.4853286790 0.4388285275
#>  [21] 0.3999652812 0.1398132907 0.4893076857 0.2774196307 0.1607170913
#>  [26] 0.6260662033 0.3238360879 0.1368795405 0.4687222476 0.5902465371
#>  [31] 0.7472331322 0.0289949871 0.2763927211 0.3514772043 0.2796187047
#>  [36] 0.5174632748 0.1043156542 0.0690797097 0.0693847552 0.2023193364
#>  [41] 0.3003037742 0.0754717936 0.6650247406 0.8771846937 0.4089033558
#>  [46] 0.7434417932 0.0556889490 0.4715188911 0.2876897553 0.0891472976
#>  [51] 0.0482615925 0.0764253595 0.0228636810 0.4954388633 0.5575243077
#>  [56] 0.5598394378 0.6615655707 0.2605402145 0.0023250595 0.5311351962
#>  [61] 0.1093243562 0.1438981704 0.0384331435 0.5436525712 0.8344086221
#>  [66] 0.5819889776 0.0670119603 0.6231586237 0.2862226920 0.7758467085
#>  [71] 0.2608609575 0.8740569542 0.4412006702 0.5394834618 0.3077856419
#>  [76] 0.3453649058 0.0401303294 0.4039356114 0.0890631604 0.0059267895
#>  [81] 0.5814584499 0.2428726486 0.0955122967 0.1454101380 0.0229667107
#>  [86] 0.0511675511 0.3749989246 0.6395189270 0.0445290813 0.3939189192
#>  [91] 0.5930542469 0.4206802773 0.3933743157 0.2106372511 0.8696570321
#>  [96] 0.1201878422 0.9283598428 0.7671617026 0.0183327988 0.5306310317
#> [101] 0.2824332689 0.1642667799 0.2422186485 0.3097589201 0.3169699829
#> [106] 0.0461064947 0.7766154274 0.6176084867 0.4046182265 0.8279041183
#> [111] 0.4517522100 0.3156802987 0.8595566936 0.0901709037 0.1117653912
#> [116] 0.2096395226 0.0005528566 0.4660106207 0.6345939486 0.4329329206
#> [121] 0.0328477093 0.4994269461 0.4665288002 0.1588345039 0.7216827875
#> [126] 0.2471166052 0.0158499628 0.1473281099 0.5403142381 0.0000000000
#> [131] 0.6868181249 0.4002920627 0.1321704736 0.5274097336 0.7717270374
#> [136] 0.8503815329 0.7491891435 0.1803031382 0.7912951009 0.5194736080
#> [141] 0.3004627488 0.2771495570 0.7817190081 0.5475957336 0.5909050078
#> [146] 0.6510383094 0.5221416367 0.2237049239 0.8458370987 0.4478975499
#> [151] 0.4755519959 0.7861689222 0.0746500941 0.2997910801 0.2083957662
#> [156] 0.0672074803 0.1819272722 0.0463626981 0.9106807305 0.8670441451
#> [161] 0.3309732831 0.3828086662 0.4295528820 0.9770364454 0.2378049410
#> [166] 0.0334033164 0.1997473504 0.2926042209 0.3285991278 0.0910525476
#> [171] 0.8339747516 0.5759822127 0.0487837887 0.8392857135 0.2321542420
#> [176] 0.4164914937 0.2528132316 0.0478132449 0.0650321757 0.6570731688
#> [181] 0.3258195272 0.4532622411 0.0535404725 0.4561143945 0.0965924621
#> [186] 0.4617203609 0.4260049940 0.3226702035 0.2179518285 0.1190478348
#> [191] 0.1179842233 0.7809801904 0.2535155282 0.3919957821 0.5134769196
#> [196] 0.8771084141 0.2589282624 0.5042717860 1.0000000000 1.0000000000