自动删除计算出的凝聚层次聚类数据的异常值

Delete outliers automatically of a calculated agglomerative hierarchical clustering data

在聚类分析中,数据集的异常值可以通过单链接方法轻松识别。现在我想自动删除异常值。我的想法是删除超过指定距离值的数据。这是我的代码和 mtcars 的示例数据:

library(cluster)
library(dendextend)
cluster<-agnes(mtcars,stand=FALSE,method="single")
dend = as.dendrogram(cluster)

在 Plot 中您可以看到生成的树状图。最后 4 辆汽车("Duster 360"、"Camaro Z28"、"Ford Pantera L"、"Maserati Bora")被识别为异常值,因此我想删除它们的孔行(数据集 mtcars)。我怎样才能自动做到这一点?例如。删除高度高于 70 的行?我尝试了很多去除异常值的可能性,但它们似乎不适用于我的数据。

非常感谢!

如果您的 "rule" 是 linking 距离,那么您基本上重新创建了最近邻离群值检测,这是数据挖掘中较旧的离群值方法之一。

Ramaswamy, Sridhar, Rajeev Rastogi, and Kyuseok Shim. "Efficient algorithms for mining outliers from large data sets." ACM Sigmod Record. Vol. 29. No. 2. ACM, 2000.

除了使用 AGNES 的单个 link 需要 O(n³) 时间,但索引可以在 O(n log n) 中执行 kNN 离群值。

试试这个:

# your code
library(cluster)
cluster<-agnes(mtcars,stand=FALSE,method="single")
dend = as.dendrogram(cluster)
plot(dend)

#new code    
hclu <- as.hclust(cluster) # convert to list that cutree() understands 
groupindexes <- cutree(hclu, h = 70) # cut at height 70 - creates 3 groups/branches
mtcars[groupindexes != 1,] # "outliers" - not in group 1 but in groups 2 and 3
mtcars[groupindexes == 1,] # all but the 4 "outliers"

结果 1 - "outliers":

                mpg cyl disp  hp drat   wt  qsec vs am gear carb
Duster 360     14.3   8  360 245 3.21 3.57 15.84  0  0    3    4
Camaro Z28     13.3   8  350 245 3.73 3.84 15.41  0  0    3    4
Ford Pantera L 15.8   8  351 264 4.22 3.17 14.50  0  1    5    4
Maserati Bora  15.0   8  301 335 3.54 3.57 14.60  0  1    5    8

结果 2:

                     mpg cyl  disp  hp drat    wt  qsec vs am gear carb
Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
(....and ~30 other rows ....)