Skip to content

Getting different results on the same data set #17

Closed

Description

@alooferyj

Hi,

Am I supposed to get different clustering result from each run on the same data set? I was running the following code:

univariate_ts_datasets = np.expand_dims(np.random.rand(200, 60), axis=2)
num_clusters = 3

CPU Model

for j in range(5):
ksc = KShapeClusteringCPU(num_clusters, centroid_init='zero', max_iter=100, n_jobs=-1)
ksc.fit(univariate_ts_datasets)

labels = ksc.labels_ # or ksc.predict(univariate_ts_datasets)
cluster_centroids = ksc.centroids_
print(labels)

My understanding is that there's nothing random in the algo since I set the centroid init to be zero. But I get different results, e.g. sometimes the first ts and second ts belong to the same cluster and sometimes they don't

Thanks,
James

Activity

  1. HaojunLi commented on Sep 18, 2024

    @HaojunLi
    Collaborator

    Hi James,
    K-Shape indeed has randomness. In your code, you set centroid init to zero, but k-Shape will randomly assign time series into clusters as an initialization. Please check here:
    image
    Also, when a cluster becomes empty during iterations, k-Shape will randomly assign a time series to that empty cluster. If you want to have a deterministic result, you need to set a random seed. I hope my answer can help.
    Best,
    Haojun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions