I am using the following code to cluster my word vectors using k-means clustering algorithm.
from sklearn import cluster
model = word2vec.Word2Vec.load("word2vec_model")
X = model[model.wv.vocab]
clusterer = cluster.KMeans (n_clusters=6)
preds = clusterer.fit_predict(X)
centers = clusterer.cluster_centers_
Given a word in the word2vec vocabulary (e.g., word_vector = model['jeep']) I want to get its cluster ID and cosine distance to its cluster center.
I tried the following approach.
for i,j in enumerate(set(preds)):
positions = X[np.where(preds == i)]
print(positions)
However, it returns all the vectors in each cluster ID and not exactly what I am looking for.
I am happy to provide more details if needed.