我想比较两个时间序列数据以查看它们彼此的相似性。
对于这个任务,我使用动态时间规整 (DTW) 算法。我已经尝试使用 Python 实现tslearn:(文档在这里)
import tslearn.metrics
import numpy as np
s1 = [0, 0, 0, 0, 0, 0, 52, 50.144, 50.144, 50.144, 50, 51.1544, 50.284, 49.214, 48.5248] # sequence 1
s2 = [0, 0, 0, 0, 0, 0, 52.9304, 51.144, 50.144, 51.144, 50.1544, 51.1544, 49.2184, 49.2184, 49.5248] # sequence 2
a = tslearn.metrics.cdist_dtw(s1, s2) # Cross similarity matrix between time series datasets
b = tslearn.metrics.dtw_path(s1, s2) # Get both the matching path and the similarity score for DTW
c = tslearn.metrics.dtw(s1, s2) # Get only the similarity score for DTW
print("Similarity: ", a)
print("*"*127)
print("Path and Similarity: ", b)
print("*"*127)
print("DTW Similarity: ", c)
print("*"*127)
我得到了这个结果:
Similarity: [[1.84218766]]
*********************************************************************************************************
Path and Similarity: ([(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (6, 7), (7, 8), (8, 8), (9, 8), (10, 8), (11, 9), (12, 10), (12, 11), (13, 12), (13, 13), (14, 14)], 1.8421876560220476)
*********************************************************************************************************
DTW Similarity: 1.8421876560220476
*********************************************************************************************************
这里让我感到困惑的是图书馆中使用的术语相似性。我无法从文档中得到任何令人满意的解释,所以我目前很困惑。
当我比较 2 个完全相同的序列时,例如:
s1 = [0, 0, 0, 0, 0, 0, 52, 50.144, 50.144, 50.144, 50, 51.1544, 50.284, 49.214, 48.5248]
s2 = [0, 0, 0, 0, 0, 0, 52, 50.144, 50.144, 50.144, 50, 51.1544, 50.284, 49.214, 48.5248]
相似度得分(变量a, b, c)将导致 0。
我的问题:
如果 0 表示我的 2 个序列相似,为什么库使用术语“相似性”而不是“不相似性”?我是否对这两个术语感到困惑?这里的相似性与距离具有相同的含义吗?
如何
tslearn计算相似度分数?