tslearn.metrics.lb_keogh(ts_query, ts_candidate=None, radius=1, envelope_candidate=None)[source]

Compute LB_Keogh.

LB_Keogh was originally presented in [1].

ts_query : array-like

Query time-series to compare to the envelope of the candidate.

ts_candidate : array-like or None (default: None)

Candidate time-series. None means the envelope is provided via envelope_candidate parameter and hence does not need to be computed again.

radius : int (default: 1)

Radius to be used for the envelope generation (the envelope at time index i will be generated based on all observations from the candidate time series at indices comprised between i-radius and i+radius). Not used if ts_candidate is None.

envelope_candidate: pair of array-like (envelope_down, envelope_up) or None
(default: None)

Pre-computed envelope of the candidate time series. If set to None, it is computed based on ts_candidate.


Distance between the query time series and the envelope of the candidate time series.

See also

Compute LB_Keogh-related envelope


This method requires a ts_query and ts_candidate (or envelope_candidate, depending on the call) to be of equal size.


[1]Keogh, E. Exact indexing of dynamic time warping. In International Conference on Very Large Data Bases, 2002. pp 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))  # doctest: +ELLIPSIS
>>> lb_keogh(ts_query=ts2,
...          ts_candidate=ts1,
...          radius=1)  # doctest: +ELLIPSIS

Examples using tslearn.metrics.lb_keogh