使用 dtwclust 在 R 中对时间序列进行聚类

Clustering time series in R with dtwclust

我第一次尝试时间序列聚类,需要一些帮助。我已经阅读了有关时间序列聚类的 tsclust 和 dtwclust 包,并决定尝试 dtwclust。

我的数据由不同位置的温度每日时间序列组成(每天一个值)。我想根据其温度序列对空间集群中的不同位置进行分组。我的第一次尝试是(只是复制了一个带有选项的示例并放置了我的数据,temp.max3)

library(dtwclust)

hc<- tsclust(temp.max3, type = "h", k = 20L,
             preproc = zscore, seed = 899,
             distance = "sbd", centroid = shape_extraction,
             control = hierarchical_control(method = "average"))

但这给了我这个错误信息

Error in stats::hclust(stats::as.dist(distmat), method, members = dots$members) : NA/NaN/Inf in foreign function call (arg 11)

我之前必须删除任何系列中存在的所有 NA,生成的 temp.max3 数据帧不包含任何 NA 值。

summary(temp.max3)
      8025           8400A            8416            8455      
 Min.   : 6.40   Min.   : 4.60   Min.   : 6.00   Min.   : 4.00  
 1st Qu.:18.80   1st Qu.:17.40   1st Qu.:18.20   1st Qu.:19.00  
 Median :23.20   Median :22.00   Median :22.60   Median :24.00  
 Mean   :23.34   Mean   :22.23   Mean   :22.71   Mean   :23.67  
 3rd Qu.:28.20   3rd Qu.:27.40   3rd Qu.:27.40   3rd Qu.:29.00  
 Max.   :41.40   Max.   :40.60   Max.   :43.00   Max.   :42.00

数据看起来像

head(temp.max3)
      8025 8400A 8416 8455
13127 16.0  14.0 13.5   14
13128 17.8  15.6 17.4   20
13129 18.2  15.2 19.2   18
13130 17.2  15.0 17.6   19
13131 17.0  13.8 15.6   17
13132 21.0  14.0 18.2   19

其中 8025、8400A、8416 和 8455 是站号(目前只有四个,但最终会扩展到 120)。可以在此保管箱中找到数据 link https://www.dropbox.com/s/xru4qnz8grhbxuo/data.csv?dl=0

任何想法,link 信息或示例将不胜感激,提前致谢

感谢 Alexis 的评论,错误消息消失,脚本 运行 正常。

library(dtwclust)

temp.max4<-t(temp.max3)

hc<- tsclust(temp.max4, type = "h", k = 2L,
             preproc = zscore, seed = 899,
             distance = "sbd", centroid = shape_extraction,
             control = hierarchical_control(method = "average"))

使用此输出

Alexis,很抱歉我不能接受评论作为解决方案。