1 回答
TA贡献1757条经验 获得超7个赞
我认为动态时间扭曲 (dtw) 可能适合您。我已经将它用于类似的事情。本质上,它允许您评估时间序列的相似性。
以下是我所知道的 python 实现:
快速dtw
dtw
dtw-python
这是它如何工作的一个体面的解释
您可以使用它来比较传入时间序列与红框中数据的相似程度。
例如:
# Event were looking for
event = np.array([10, 100, 50, 60, 50, 70])
# A matching event occurring
event2 = np.array([0, 7, 12, 4, 11, 100, 51, 62, 53, 72])
# A non matching event
non_event = np.array([0, 5, 10, 5, 10, 20, 30, 20, 11, 9])
distance, path = fastdtw(event, event2)
distance2, path2 = fastdtw(event, non_event)
这将产生一组指数,其中两个时间序列最匹配。在这一点上,您可以通过您喜欢的任何方法进行评估。我粗略地查看了值的相关性
def event_corr(event,event2, path):
d = []
for p in path:
d.append((event2[p[1]] * event[p[0]])/event[p[0]]**2)
return np.mean(d)
print("Our event re-occuring is {:0.2f} correlated with our search event.".format(event_corr(event, event2, path)))
print("Our non-event is {:0.2f} correlated with our search event.".format(event_corr(event, non_event, path2)))
产生:
Our event re-occurring is 0.85 correlated with our search event.
Our non-event is 0.45 correlated with our search event.
添加回答
举报