tslearn.metrics.lb_keogh¶
- 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].
- Parameters:
- ts_queryarray-like, shape=(sz1, 1) or (sz1,)
Univariate query time-series to compare to the envelope of the candidate.
- ts_candidateNone or array-like, shape=(sz2, 1) or (sz2,) (default: None)
Univariate candidate time-series. None means the envelope is provided via envelope_candidate parameter and hence does not need to be computed again.
- radiusint (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.
- Returns:
- float
Distance between the query time series and the envelope of the candidate time series.
See also
lb_envelope
Compute LB_Keogh-related envelope
Notes
This method requires a ts_query and ts_candidate (or envelope_candidate, depending on the call) to be of equal size.
References
[1]Keogh, E. Exact indexing of dynamic time warping. In International Conference on Very Large Data Bases, 2002. pp 406-417.
Examples
>>> 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...