Suppose that we need to compare 2 time series (quite look-alike),
- They're quite look-alike but if we compare point-to-point, they're clearly very different!
- With DTW, we compare:
- hollows of series 1 with ones of series 2.
- cambers of series 1 with ones of series 2.
- Dynamic Time Warping is used to compare the similarity or calculate the distance between two arrays or time series with different length.
- An example: Voice of a man. He can speak fast. He can speak slowly. However, the both voices are his. If we don't use DTW but Euclidian distance, the distance is very large → there are 2 voices → wrong prediction!
- Sound Pattern Recognition: detect the same kind of sound pattern (like the above example).
- Stock Market:
- Divide 2 time series into equal points.
- Calculate distance between 1st point in TS1 with all points in TS2 and then store the min.
- Move to 2nd point.
- Repeat step 2 & 3 but with 2nd point as a reference point.
- Add up all stored distances. This is a true measure between 2 time series.
👉 Check this video fore a more explanation.
👉 Another option: dtw-python
👉 fastdtw (an approximate Dynamic Time Warping (DTW) algorithm that provides optimal or near-optimal alignments with an O(N) time and memory complexity)