私はちょうどピークがあるべき場所、それが判断するほとんど不可能ですが、ggplotで2D密度平滑で描かれた場合、私はこれらを取得するだけで、データポイントでデータ/プロットの次のタイプ多くの異常値を含む2Dデータのクラスタリングのための最適化されたK平均の最適化?より良いアプローチ?
探しています本当に素敵な山々。私が目にするのは、〜10点のグループを見つけたいと思っています。 「有効なグループ」の正確な数は、もちろん議論のために上がっています。ここ
データ: https://pastebin.com/5wquw7UF
library(ggplot2)
library(colorRamps)
library(tclust)
ggplot(data = df, aes(x = x, y = y)) +
stat_density2d(geom = "raster",
aes(fill = ..density..),
contour = FALSE) +
geom_point(col = "white", alpha = 0.1) +
scale_x_continuous(expand = c(0,0),
limits = c(0,1)) +
scale_y_continuous(expand = c(0,0),
limits = c(0,1)) +
theme_tufte(base_size = 11, base_family = "Helvetica") +
theme(axis.text = element_text(color = "black"),
panel.border = element_rect(colour = "black", fill=NA, size=0.7),
legend.key.height = unit(2.5,"line"),
legend.key.width = unit(1, "line")) +
scale_fill_gradientn(name = "Density",
colours = matlab.like(1000))
私はパッケージtclust
で、トリミングされたクラスタリングに見てきました。データを手書きして、私は以下を考え出すことができました。しかし、私がどれほど多くのパラメータを使っていても、視覚的に感じるような「タイト」なグループは得られないようです。特にグループ5は所属していない場所に侵入しているようだ。グループ10もちょっと奇妙ですが、後で破棄するのに十分に隔離されています。
これに対して、より良い方法がありますか、それともパラメータを正しく設定する方法がわからないのですか?
set.seed(2)
trimmed_cluster <- tclust(
x = df,
k = 10, # 9
alpha = 0.1, # 0.1
drop.empty.clust = FALSE,
equal.weights = TRUE,
restr = c("sigma", "eigen"), # sigma
restr.fact = 1
)
df$cluster <- trimmed_cluster$cluster
trimmed_cluster_centers <- data.frame(t(trimmed_cluster$centers))
df_clustered <- subset(df, cluster != 0)
ggplot(data = df, aes(x = x, y = y)) +
stat_density2d(geom = "raster",
aes(fill = ..density..),
contour = FALSE) +
geom_point(data = df_clustered, aes(x = x, y = y, col = as.factor(cluster))) +
geom_text(data = trimmed_cluster_centers,
aes(x = x, y = y, label = as.character(1:length(trimmed_cluster_centers$x))),
size = 5,
fontface = "bold",
col = "yellow2") +
scale_x_continuous(expand = c(0,0),
limits = c(0,1)) +
scale_y_continuous(expand = c(0,0),
limits = c(0,1)) +
theme_tufte(base_size = 11, base_family = "Helvetica") +
theme(axis.text = element_text(color = "black"),
panel.border = element_rect(colour = "black", fill=NA, size=0.7),
legend.key.height = unit(0.8,"line"),
legend.key.width = unit(0.5, "line")) +
scale_fill_gradientn(name = "Density",
colours = matlab.like(1000)) +
scale_color_brewer(name = "cluster ID",
type = "qual",
palette = "Spectral")
**密度ベース**クラスタリングの古典的なDBSCANアルゴリズムはどうですか? –
これは完璧です*と私はほとんど今尋ねて愚かな感じ! –