tslearn-team / tslearn

The machine learning toolkit for time series analysis in Python
https://tslearn.readthedocs.io
BSD 2-Clause "Simplified" License
2.83k stars 331 forks source link

TimeSeriesKMeans with custom metric #474

Open trintingnant opened 11 months ago

trintingnant commented 11 months ago

Hi,

I would like to do kDBA, but using a custom metric for computing the DTW alignments (not available in either scikit or scipy).

Now, dtw_variants has the dtw_path_from_metric function, so there it is always possible to compute dtw alignments for any pair of timeseries, passing the metric either as a functional, or by passing a pre-computed distance matrix (which for my purposes is not super-feasible).

Now, the problem is that the dba module only ever uses dtw_path, and so is always, at least implicitly, using euclidean distance. Is there a straigtforward way of passing custom metrics to TimeSeriesKMeans such that it computes the dtw alignments using a custom metric? It probably isn't too hard to change all calls to dtw_path to dtw_path_from_metric, conditional on a metric being provided. Just checking if there is an easier way.

Thanks,

trintingnant commented 10 months ago

[edit] got a working version of this now. If anyone is interested. Would need more testing though.