Dynamic time warping

Next, however, I want to introduce another model, which uses a completely different algorithm. This algorithm is called dynamic time warping. What it does is give you a metric that represents the similarity between two time series:

  1. To get started, we'll need to pip install the fastdtw library:
!pip install fastdtw 
  1. Once that is installed, we'll import the additional libraries we'll need:
from scipy.spatial.distance import euclidean 
from fastdtw import fastdtw 
  1. Next, we'll create the function that will take in two series and return the distance between them:
def dtw_dist(x, y): 
    distance, path = fastdtw(x, y, dist=euclidean) 
    return distance 
  1. Now, we'll split our 18 years' worth of time series data into distinct five-day ...

Get Python Machine Learning Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.