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

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

我正在尝试 运行 来自 Kaggle 的代码。使用 DTW 对时间序列进行聚类。 更具体的部分: 在[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

作为参数之一,作者声称“step_pattern=rabinerJuangStepPattern(2, "c"))”但是,当我 运行 它时,我得到了提到的错误。 有谁知道可能出了什么问题?

谢谢!

您需要先像这样从 dtw 包中导入此函数:

from dtw import *

如果你滚动到 Kaggle 页面的顶部,你可以看到它也被导入那里。