# Suitable distance metric for time-series clustering with respect to location of shapes

I'm doing clustering on time-series (each time-series has the information for one day = 24 hours). For the clustering purpose, it's important for me to consider the time period in which the shape of time-series is different from the baseline. So, I'm looking for an appropriate distance metric.

For example, let's consider these 4 time-series, and I want to cluster them into two groups. Apperaently, for k=2, time-series 1 and 2 are more similar and considered as one cluster and time-series 3 and 4 are inside another cluster. However, when I use the commonly used Euclidean distance metric, the calculated distance between all time-series is the same since it considers one to one mapping between points, and does not account for how far these shapes are. I have tried Dynamic Time Warping (DTW) as well since its application matches what I want to do here, but my clustering results in a larger-scale dataset are even less promising compared to what Euclidean distance obtains (I'm using the default MATLAB command line for DTW, so I'm not sure if I'm utilizing it efficiently).

My question is what distance metric is more appropriate to capture the similarity in this case.

• Are 1 and 4 in one cluster because they occur during the night/dark? (Wraparound) – Rob Jul 19 '18 at 16:34
• That's an interesting point you brought up! But at this time I'm considering each time-series as 24 points (starting from 1 to 24) and just looking for a metric that shows me the distance between #4 and #3 is lower compared to #4 and #2 or #4 and #1 based on visual intuition. – N.researcher Jul 19 '18 at 17:07
• Have you checked the dtwclust package - github.com/asardaes/dtwclust – wololo Jul 20 '18 at 23:38
• How about the integral of t * f(t) – Rohit Chatterjee Jul 21 '18 at 12:57
• (Or in your case, sum(n * f(n)), n ranging from 1 to 24) – Rohit Chatterjee Jul 21 '18 at 13:06

## 1 Answer

Minor point, DTW is not a metric, just a measure.

The measure you need is constrained DTW (or cDTW),

With enough data you can learn the constraint, but here is it clear it should be about 1/3 the length of the time series.

This tutorial will tell you all you need to know http://www.cs.unm.edu/~mueen/DTW.pdf

eamonn