【问题标题】:Self Organising Map R自组织图 R
【发布时间】:2014-07-19 20:53:11
【问题描述】:

我使用 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)

任何帮助表示赞赏

谢谢

【问题讨论】:

  • 您能提供一个最小的可重现示例吗?我建议你阅读this
  • 我想说?raster::cellFrom可以做到这一点
  • 嗨,保罗,请看下面,皮埃尔的问候

标签: r self-organizing-maps


【解决方案1】:

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

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)

谢谢

皮埃尔

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 2016-07-11
    • 2013-08-16
    • 1970-01-01
    • 2022-10-25
    • 2010-12-10
    相关资源
    最近更新 更多