Skip to contents

This function uses the mean as the ensemble score.

Usage

average_ensemble(X)

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.

Value

The ensemble 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 <- average_ensemble(Y)
ens
}
#>   [1] 0.35450653 0.20360566 0.26784708 0.06424385 0.01779103 0.31278162
#>   [7] 0.10273460 0.23223313 0.25374899 0.04762126 0.19973498 0.05481644
#>  [13] 0.22185015 0.02853384 0.14857941 0.43025498 0.04995008 0.38422235
#>  [19] 0.25276647 0.18984276 0.19128031 0.07339301 0.20416019 0.14071074
#>  [25] 0.10795693 0.27849691 0.14869747 0.06322518 0.20862713 0.29595831
#>  [31] 0.36132995 0.02549242 0.13848280 0.16478087 0.12504616 0.26706655
#>  [37] 0.05231673 0.03759518 0.03853421 0.09803491 0.14149844 0.04937910
#>  [43] 0.28317092 0.45825484 0.18241945 0.32518122 0.04270858 0.20314836
#>  [49] 0.12821677 0.04737759 0.01918231 0.04166233 0.01791865 0.22545090
#>  [55] 0.25575930 0.25599220 0.29723948 0.13260730 0.01163594 0.25834234
#>  [61] 0.04409476 0.09093576 0.02849731 0.22138156 0.39188279 0.27984707
#>  [67] 0.03743845 0.28620184 0.12960448 0.36790964 0.13066469 0.44999232
#>  [73] 0.21166301 0.23716473 0.14194814 0.15624674 0.02465892 0.19163449
#>  [79] 0.05423587 0.01104798 0.26352125 0.12427260 0.05254299 0.06635906
#>  [85] 0.01468632 0.04069771 0.17709713 0.30650664 0.03805044 0.18785952
#>  [91] 0.28964315 0.20296554 0.19257952 0.11333140 0.42734667 0.08310622
#>  [97] 0.48352782 0.38557161 0.01488513 0.21630393 0.13449505 0.07750095
#> [103] 0.11389163 0.13893440 0.15952438 0.02757615 0.36664725 0.27594328
#> [109] 0.18489490 0.40989585 0.19419837 0.15315609 0.44546037 0.04625249
#> [115] 0.04624977 0.10877886 0.01165039 0.20657929 0.26514091 0.19243144
#> [121] 0.02666236 0.20512435 0.19935124 0.08339307 0.34330557 0.13103807
#> [127] 0.01783943 0.07965787 0.22043041 0.01065364 0.33540069 0.20896043
#> [133] 0.06185966 0.23555991 0.36733971 0.43263123 0.36730494 0.08725847
#> [139] 0.38901292 0.23166865 0.15058348 0.13836008 0.35831270 0.24241106
#> [145] 0.26337547 0.28687319 0.23056647 0.09598972 0.43028884 0.20728224
#> [151] 0.22676282 0.38954954 0.03025057 0.16421737 0.10257606 0.03633981
#> [157] 0.10087619 0.03252201 0.48620092 0.42683305 0.15077651 0.18183822
#> [163] 0.20324461 0.56727937 0.11892340 0.01863609 0.11042381 0.13326363
#> [169] 0.16308019 0.03725615 0.39995787 0.26466114 0.02909656 0.41556347
#> [175] 0.12940595 0.19839730 0.12743193 0.03945262 0.04212177 0.28798701
#> [181] 0.16889292 0.21410068 0.03113148 0.20110441 0.05158191 0.21697267
#> [187] 0.20240687 0.16324679 0.09266796 0.07174949 0.05058047 0.36627530
#> [193] 0.13036955 0.17774031 0.23907718 0.43599772 0.12038531 0.22681006
#> [199] 0.87429229 0.99649522