tslearn.metrics.lb_keogh¶
- tslearn.metrics.lb_keogh(ts_query, ts_candidate=None, radius=1, envelope_candidate=None)[source]¶
计算 LB_Keogh。
LB_Keogh最初在[1]中提出。
- Parameters:
- ts_queryarray-like, shape=(sz1, 1) or (sz1,)
单变量查询时间序列以与候选者的包络进行比较。
- ts_candidateNone or array-like, shape=(sz2, 1) or (sz2,) (default: None)
单变量候选时间序列。None 表示通过 envelope_candidate 参数提供包络,因此不需要再次计算。
- radiusint (default: 1)
用于生成包络线的半径(时间索引i处的包络线将基于候选时间序列中索引在i-radius和i+radius之间的所有观测值生成)。如果ts_candidate为None,则不使用。
- envelope_candidate: pair of array-like (envelope_down, envelope_up) or None
- (default: None)
候选时间序列的预计算包络。如果设置为None,则基于ts_candidate进行计算。
- Returns:
- float
查询时间序列与候选时间序列包络之间的距离。
另请参阅
lb_envelope计算与LB_Keogh相关的包络
注释
此方法要求ts_query和ts_candidate(或envelope_candidate,取决于调用)的大小相等。
参考文献
[1]Keogh, E. 动态时间规整的精确索引。在《国际大型数据库会议》中,2002年。第406-417页。
示例
>>> ts1 = [1, 2, 3, 2, 1] >>> ts2 = [0, 0, 0, 0, 0] >>> env_low, env_up = lb_envelope(ts1, radius=1) >>> lb_keogh(ts_query=ts2, ... envelope_candidate=(env_low, env_up)) 2.8284... >>> lb_keogh(ts_query=ts2, ... ts_candidate=ts1, ... radius=1) 2.8284...