时间序列曲线相似性

使用DTW比较曲线相似性

from dtaidistance import dtw as dtwd
import numpy as np
import matplotlib.pyplot as plt
from labellines import labelLines


x=np.arange(0,2*np.pi,0.1)
y=np.sin(x)
plt.plot(x, y,label='y')

for i in [0,1,2,3]:
    z=np.sin(x+(np.pi/2)*i)
    distance_s = dtwd.distance(y, z,use_c=True)
    plt.plot(x,z,label=str(i))
    print(distance_s)

#简单的设置legend(设置位置)
#位置在右上角
plt.legend(loc = 'upper right')
0.0
3.579437105036351
5.914434728535967
3.3300802329969446

在这里插入图片描述
峰谷想错的时候,距离最大

猜你喜欢

转载自blog.csdn.net/weixin_44831720/article/details/126060822
今日推荐