【问题标题】:Plot clusters of observations which represent a time series绘制代表时间序列的观测集群
【发布时间】:2021-02-20 14:45:18
【问题描述】:

我正在使用dtwclust 包对包含多元时间序列数据的数据框进行聚类。在对这些数据进行聚类后,我想根据聚类而不是时间序列数据生成一个以 $k$ 组呈现观察结果的图!

dtw_cluster2 = tsclust(sample_data, type="partitional",k=6,preproc = zscore,distance="dtw_basic",centroid = "pam",trace=T)

然后绘制,

plot(dtw_cluster2)

我得到了:

我不想要这些情节!我想要观察集群。我试图从tsclust() 中提取集群为dtw_cluster2$cluster,但出现错误"$ operator not defined for this S4 class"

我的数据集看起来像

 V1        V2         V3         V4          V5         V6         V7
1  0 0.1182197 0.09057301 0.08089888 0.003350084 0.00000000 0.00000000
2  0 0.1276078 0.09242144 0.01348315 0.060301508 0.02245599 0.02298152
3  0 0.1369958 0.12569316 0.03595506 0.159128978 0.04491198 0.04596305
4  0 0.1029207 0.10166359 0.08089888 0.201005025 0.06736798 0.06894457
5  0 0.1585535 0.14510166 0.08089888 0.112227806 0.08982397 0.09192609
6  0 0.1488178 0.00000000 0.07415730 0.212730318 0.11227996 0.11490761

编辑

我想根据集群绘制观察结果,类似于“知道我正在使用dtw 距离”:

【问题讨论】:

    标签: r plot cluster-analysis


    【解决方案1】:

    查看结果,可以看到:

    str(dtw_cluster2)
    
    Formal class 'PartitionalTSClusters' [package "dtwclust"] with 20 slots
      #.. (NB here there are things I've skipped )
      ..@ distance : chr "dtw_basic"
      ..@ centroid : chr "pam"
      ..@ preproc  : chr "zscore"
      ..@ k        : int 2
      ..@ cluster  : int [1:6] 1 1 1 2 1 2
      #.. (NB here there are things I've skipped )
    

    所以你可以这样提取集群:

    dtw_cluster2@cluster
    [1] 1 1 1 2 1 2
    

    给定:

    library(dtwclust)
    dtw_cluster2 <- tsclust(sample_data, type="partitional",
                                         k=2,
                                         preproc = zscore,
                                         distance="dtw_basic",
                                         centroid = "pam",
                                         trace=T)
    

    有数据:

    sample_data <-
    structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L), V2 = c(0.1182197, 
    0.1276078, 0.1369958, 0.1029207, 0.1585535, 0.1488178), V3 = c(0.09057301, 
    0.09242144, 0.12569316, 0.10166359, 0.14510166, 0), V4 = c(0.08089888, 
    0.01348315, 0.03595506, 0.08089888, 0.08089888, 0.0741573), V5 = c(0.003350084, 
    0.060301508, 0.159128978, 0.201005025, 0.112227806, 0.212730318
    ), V6 = c(0, 0.02245599, 0.04491198, 0.06736798, 0.08982397, 
    0.11227996), V7 = c(0, 0.02298152, 0.04596305, 0.06894457, 0.09192609, 
    0.11490761)), class = "data.frame", row.names = c(NA, -6L))
    

    【讨论】:

    • 感谢您的回答,但是如何根据集群绘制观察结果?
    • @Flore 嗨,您能否更好地解释所需的输出?你的情节已经被集群分面了。
    • 更清楚一点。你在 x 和 y 轴上想要什么?
    • 我不确定!但我认为 x 代表来自 CLUSTERS 中的多元时间序列的观察结果,y 将是距离。 x 和 y 还有其他选择吗?
    • 如我所见,每个时间序列都是单变量的,每个时间序列都有超过 1 个观察值。此外,正如您在dtw_cluster2@distmat 中看到的那样,距离对于 ts 的每个组合都是一个。我认为散点图不适合这种分析。尝试阅读this paper 澄清一下。
    猜你喜欢
    • 2023-03-21
    • 2023-03-18
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 2018-08-20
    • 2021-10-24
    相关资源
    最近更新 更多