我通过安装了python DTW(动态时间规整)模块

python -m pip install dtw


当我尝试使用from dtw import dtw导入模块时(我遵循http://nbviewer.jupyter.org/github/pierre-rouanet/dtw/blob/master/simple%20example.ipynb),我得到一个ImportError: cannot import name dtw。我检查了dtw.py中是否存在dtw.pycC:\Python27\Lib\site-packages文件。有人知道该问题的解决方案吗?

最佳答案

如果您正在寻找速度

from cdtw import pydtw
from dtaidistance import dtw
from fastdtw import fastdtw
from scipy.spatial.distance import euclidean
s1=np.array([1,2,3,4],dtype=np.double)
s2=np.array([4,3,2,1],dtype=np.double)

%timeit dtw.distance_fast(s1, s2)
4.1 µs ± 28.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%timeit d2 = pydtw.dtw(s1,s2,pydtw.Settings(step = 'p0sym', window = 'palival', param = 2.0, norm = False, compute_path = True)).get_dist()
45.6 µs ± 3.39 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%timeit d3,_=fastdtw(s1, s2, dist=euclidean)
901 µs ± 9.95 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)


fastdtw比dtaidistance lib慢219倍,比cdtw慢20倍

考虑改变。这是dtaidistance git:

https://github.com/wannesm/dtaidistance

要安装,只需:

pip install dtaidistance

07-24 09:18