# K-medoids algorithm for time series with varying lengths

Can time series having multiple lengths be clustered using the k-medoids algorithm. I am essentially looking for a way to find a representative pattern from a set of time series using the k-medoids centroid.

## 2 Answers

Not a big deal, but DTW is not a metric, it is only a measure.

Paper [a] does exactly what you want.

## However, if you have one long time series, as opposed to many short time series, they you should look at time series snippets [b].

You can adapt it via a suitable distance. Unlike k-means, k-medoid centers are chosen directly from data. So, you don't have to implement addition operation between data samples. It just remains to use a well-defined distance, i.e. $$d(x_i,x_j)$$. Several distances for time series with different lengths exist, e.g. Dynamic Time Warping. This library in R has many of them and also implements K-medoids algorithm with a lot of distance options.