I am working on a clustering analysis of time series data in R using the dtwclust package, specifically the tsclust function. My goal is to perform multiple runs of the clustering and extract cluster labels from each run.
Here's an example code (from dtwclust documentation):
# Load data
data(uciCT)
# Reinterpolate to same length
series <- reinterpolate(CharTraj, new.length = max(lengths(CharTraj)))
# Subset for speed
series <- series[1:20]
labels <- CharTrajLabels[1:20]
# Making many repetitions
pc.l2 <- tsclust(series, k = 4L,
distance = "L2", centroid = "pam",
seed = 3247, trace = TRUE,
control = partitional_control(nrep = 10L))
# Cluster validity indices
sapply(pc.l2, cvi, b = labels)
The code works fine, but I'm having trouble accessing cluster labels from multiple runs. Specifically, I want to extract cluster labels from each run. Modifying the code as follow (setting one single run), extracting cluster labels is not a problem
# Making many repetitions
pc.l2 <- tsclust(series, k = 4L,
distance = "L2", centroid = "pam",
seed = 3247, trace = TRUE,
control = partitional_control(nrep = 1L))
# Extracting cluster labels
labels <- pc.l2@cluster
This allows me to extract cluster labels, but I need to perform multiple runs, and I'm unsure how to access cluster labels from each run.
Can anyone provide guidance on how to access cluster labels from multiple runs of the tsclust function in the dtwclust package?