tslearn/kmeans-metric-params-mismatch
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| tslearn | warning | none, edit by hand | All versions |
TimeSeriesKMeans defaults to metric="euclidean", where metric_params is never passed to scipy.spatial.distance.cdist. When metric="dtw", forwarding metric_params={"gamma": ...} raises TypeError: _cdist_dtw() got an unexpected keyword argument 'gamma' because gamma is only accepted by metric="softdtw".
km = TimeSeriesKMeans(n_clusters=3, metric="dtw", metric_params={"gamma": 0.5}, random_state=0)km = TimeSeriesKMeans(n_clusters=3, metric="softdtw", metric_params={"gamma": 0.5}, random_state=0)What the rule reports
Section titled “What the rule reports”TimeSeriesKMeans(...) calls that pass metric_params={"gamma": ...} with metric="dtw", or pass a non-None metric_params while metric is "euclidean" or omitted.
How to fix it
Section titled “How to fix it”Set metric="softdtw" when configuring gamma, set metric="dtw" when passing DTW constraint keys (global_constraint, sakoe_chiba_radius, itakura_max_slope), or remove metric_params for Euclidean k-means.
Diagnostic message
Section titled “Diagnostic message”TimeSeriesKMeans only forwards metric_params={"gamma": ...} when metric="softdtw" (passing gamma with metric="dtw" raises TypeError, and metric_params is ignored when metric="euclidean").See all rules in the tslearn pack.