np.dot对于200维numpy数组将返回0,即使该数组非零。请参见下面的代码
from math import sqrt
def dist(u, v):
print(np.dot(u,u))
print(sum(u**2))
return 1 - (np.dot(u, v) / (sqrt(np.dot(u, u)) * sqrt(np.dot(v, v))))
from nltk.cluster import KMeansClusterer
import nltk
Num_Clusters = 5
X = model.wv.vectors
kclusterer = KMeansClusterer(Num_Clusters, distance = dist, repeats = 25)
assigned_clusters = kclusterer.cluster(X, assign_clusters=True)
打印输出-
0.0
249.0185429678968
0.0
249.0185429678968
0.0
249.0185429678968