【问题标题】:NameError: name 'rabinerJuangStepPattern' is not defined when using dtwNameError:使用 dtw 时未定义名称“rabinerJuangStepPattern”
【发布时间】:2020-10-16 00:45:38
【问题描述】:

我正在尝试从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"))”但是,当我运行它时,我得到了提到的错误。 有谁知道可能出了什么问题?

谢谢!

【问题讨论】:

  • 你不应该复制你并不真正理解的代码。这里rabinerJuangStepPattern似乎是一个函数,但你没有创建或导入它。
  • 很可能是因为这是作为笔记本运行的,您忘记在它之前运行定义此函数的 sn-p。

标签: python time-series cluster-analysis nameerror dtw


【解决方案1】:

你需要先像这样从 dtw 包中导入这个函数:

from dtw import *

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

【讨论】:

  • 感谢您的回答!但是我已经导入了,错误依旧。
  • 好的,你也安装了 dtw-python 包吗?请确保您安装的是“dtw-python”而不是“dtw”包。
  • 我都安装了。现在我卸载了这两个并再次安装了 dtw-python 但我仍然收到错误。
  • 好吧,这很奇怪。如果您在笔记本中使用它,您是否在使用函数运行代码块之前运行了导入包的代码块?
  • 是的。我在运行“?dtw”时得到:“dtw(x, y, dist, warp=1, w=inf, s=1.0) 计算两个序列的动态时间规整 (DTW)。”貌似没有step_pattern之类的参数...
猜你喜欢
  • 1970-01-01
  • 2018-01-24
  • 1970-01-01
  • 2016-11-30
  • 2017-03-08
  • 2018-05-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多