Skip to content

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)

Calls to TimeSeriesKMeans, KShape, or KernelKMeans outside test files that omit random_state=.

Pass an explicit integer seed such as random_state=0.

$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.