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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.