我正在使用dtwclust软件包对包含多变量时间序列数据的数据帧进行聚类。在对这些数据进行聚类后,我想根据聚类,而不是时间序列数据,生成一个图表来呈现$k$组中的观察结果!
dtw_cluster2 = tsclust(sample_data, type="partitional",k=6,preproc = zscore,distance="dtw_basic",centroid = "pam",trace=T)然后去画图,
plot(dtw_cluster2)我得到了:

我不想要这些情节!我想要一组观察结果。我试图以dtw_cluster2$cluster的形式从tsclust()中提取集群,但是我得到了一个错误的"$ 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距离”中的聚类来绘制观察值:

发布于 2020-11-08 22:30:16
查看结果,您可以看到:
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))https://stackoverflow.com/questions/64738806
复制相似问题