tslearn/kmeans-unseeded-random-state
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| tslearn | warning | unsafe, with xpd check --fix --unsafe-fixes |
All versions |
TimeSeriesKMeans, KShape, and KernelKMeans default random_state=None, which draws initial centroids from the global NumPy RNG. Without an explicit seed, cluster labels and barycenters can change across runs.
km = TimeSeriesKMeans(n_clusters=3, metric="dtw")km = TimeSeriesKMeans(n_clusters=3, metric="dtw", random_state=0)What the rule reports
Section titled “What the rule reports”Calls to TimeSeriesKMeans, KShape, or KernelKMeans outside test files that omit random_state=.
How to fix it
Section titled “How to fix it”Pass an explicit integer seed such as random_state=0.
Diagnostic message
Section titled “Diagnostic message”$C without random_state= initializes cluster centroids from the global NumPy RNG and changes assignments across runs. Pass random_state= (for example random_state=0) for reproducible clustering.See all rules in the tslearn pack.