如何获得dtwclust的结果

时间:2017-02-13 06:38:26

标签: r cluster-analysis

现在我正在使用dtwclust包(感谢作者Alexis Sarda-Espinosa& Alexis Sarda~)

我遇到了一个简单的问题。这是我的代码。

sc <- read.table("D:/handling data/confirm.csv", header=T, sep="," )
rownames(sc) <- sc$STDR_YM_CD
sc$STDR_YM_CD <- NULL
sc <- t(sc)
hc_sbd <- dtwclust(sc, type = 'h', k=3L, method = 'average', preproc = zscore,
               distance = 'dtw', control = list(trace=TRUE) )

plot(hc_sbd@cluster)
plot(hc_sbd, type='sc')
plot(hc_sbd, type='series', clus=2)
plot(hc_sbd, type='centroids', clus=2)

head(hc_sbd)
write.xlsx(hc_sbd, "D:/handling data/tab1clustn.xlsx")

我得到了这张照片。 我想用群集标签导出我的数据。像第二张照片。

enter image description here enter image description here

这是我的数据链接 http://blogattach.naver.com/e772fb415a6c6ddafd137d427d9ee7953f6e9146/20170207_141_blogfile/khm2963_1486442387926_THgZRt_csv/confirm.csv?type=attachment

1 个答案:

答案 0 :(得分:3)

我认为STDR_YM_CD是您想要与DTW集群的唯一标识符。

sc <- read.table("D:/handling data/confirm.csv", header=T, sep="," )
df.labels <- sc$STDR_YM_CD    #rownames(sc) <- sc$STDR_YM_CD
sc$STDR_YM_CD <- NULL
sc <- t(sc)

hc_sbd <- dtwclust(sc, type = 'h', k=3L, method = 'average', preproc = zscore,
           distance = 'dtw', control = list(trace=TRUE) )

hc.clust <- data.frame(STDR_YM_CD = df.labels, dtwclust = hc_sbd@cluster)

sc <- merge(sc,hc.clust, by.x = "STDR_YM_CD", by.y = "STDR_YM_CD")

我只是提取标签,你试图聚类的变量,然后我从dtwclust结果创建一个新的数据框,列名为dtwclust。我认为根据我们独特的标签将它们合并。还有其他方法可以做到这一点,但这是一个选项。我希望它有所帮助!