pythontime-seriescluster-analysisnameerrordtw

NameError: name 'rabinerJuangStepPattern' is not defined when using dtw


I'm trying to run this code from Kaggle. For clustering time series using DTW. More specifically the part: In[24/25]:

"""
From a list of series, compute a distance matrix by computing the 
DTW distance of all pairwise combinations of series.
"""
diff_matrix = {}
cross = itertools.product(cols, cols)
for (col1, col2) in cross:
    series1 = daily_sales_item_lookup_scaled_weekly[col1]
    series2 = daily_sales_item_lookup_scaled_weekly[col2]
    diff = dtw(
        series1, 
        series2,
        keep_internals=True, 
        step_pattern=rabinerJuangStepPattern(2, "c")
        )\
        .normalizedDistance
    diff_matrix[(col1, col2)] = [diff]
return diff_matrix

As one of the parameters, the authors claim "step_pattern=rabinerJuangStepPattern(2, "c"))" however, when I run it, I get the error mentioned. Does anyone know what might be wrong?

Thank you!


Solution

  • You need to import this function from the dtw package like this first:

    from dtw import *
    

    If you scroll to the top of the Kaggle Page you can see that it is imported there too.