1

我使用 R 中的 Kohonen 包创建了一个 SOM 地图,并希望在地图上标识一个特定的数据点位置。即所使用的系列是由 2 列组成的矩阵,并且增加了一行,我如何在地图本身或任何特定行上标记最后一次观察的位置?我使用的代码如下:

require(kohonen)
pretty_palette <- c("#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')
data_train <- na.omit(cbind(dataseries_1,dataseries_2))
data_train_matrix <- as.matrix(scale(data_train))
som_grid <- somgrid(xdim = 10, ydim=10, topo="hexagonal")

som_model <- som(data_train_matrix, 
             grid=som_grid, 
             rlen=100, 
             alpha=c(0.05,0.01), 
             keep.data=TRUE,
             n.hood="circular")

som_cluster <- cutree(hclust(dist(som_model$codes)), 4)
plot(som_model, type="mapping", bgcol =pretty_palette[som_cluster] , main = "Regimes Map")
add.cluster.boundaries(som_model, som_cluster)

任何帮助表示赞赏

谢谢

4

1 回答 1

0

我在代码顶部添加了两行来表示一些数据。我想要的是能够在地图上标记脚本绘制的位置:

datapoint_to_flag <- tail(data_train_matrix,1)

通过在单元格上插入一个文本,其值(或最接近)与datapoint_to_flag我到目前为止编写的代码创建一些随机序列,然后将它们绘制在 4 个集群中,我不知道如何编写的位是本地化的datapoint_to_flag位地图……如果这有意义的话。

require(kohonen)
pretty_palette <- c("#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')

dataseries1 <- rnorm(1000, mean = 0, sd = 3)
dataseries2 <- rnorm(1000, mean = 0, sd = 1)



data_train <- na.omit(cbind(dataseries1,dataseries2))
data_train_matrix <- as.matrix(scale(data_train))
som_grid <- somgrid(xdim = 20, ydim=20, topo="hexagonal")

som_model <- som(data_train_matrix, 
             grid=som_grid, 
             rlen=1000, 
             alpha=c(0.05,0.01), 
             keep.data=TRUE,
             n.hood="circular")

som_cluster <- cutree(hclust(dist(som_model$codes)), 4)
plot(som_model, type="mapping", bgcol =pretty_palette[som_cluster] , main = "Regimes Map")
add.cluster.boundaries(som_model, som_cluster)

datapoint_to_flag <- tail(data_train_matrix,1)

谢谢

皮埃尔

于 2014-05-31T14:46:08.433 回答