def cluster(self, vectors, assign_clusters=False, ClusterNum=None, DisType='cos', Stype='avg', trace=False): # stores the merge order #------------------------------------------------- self._distMap.clear() # 每次聚类不同样本之前必须更新 #------------------------------------------------- l = len(vectors) if ('cos' == DisType): for i in range(l): for j in range(i + 1, l): self._distMap[(i, j)] = cosine_distance( vectors[i], vectors[j]) elif ('euc' == DisType): for i in range(l): for j in range(i + 1, l): self._distMap[(i, j)] = euclidean_distance( vectors[i], vectors[j]) self._dendrogram = Dendrogram( [numpy.array(vector, numpy.float64) for vector in vectors]) result = VectorSpaceClusterer.cluster(self, vectors, assign_clusters, ClusterNum, Stype, trace) if (2 == len(vectors[0])): # 二维样本则显示可视化结果 self.draw_2D(vectors, result) return result
def cluster(self, vectors, assign_clusters=False,ClusterNum=None, DisType='euc',Stype='mean',trace=False): # stores the merge order #------------------------------------------------- self._distMap.clear() # 每次聚类不同样本之前必须更新 #------------------------------------------------- l = len(vectors) if(0==l): return [] if('cos'==DisType): for i in range(l): for j in range(i+1,l): self._distMap[(i,j)] = cosine_distance(vectors[i], vectors[j]) elif('euc'==DisType): for i in range(l): for j in range(i+1,l): self._distMap[(i,j)] = euclidean_distance(vectors[i], vectors[j]) result = VectorSpaceClusterer.cluster(self, vectors,assign_clusters,ClusterNum, Stype, trace) #/////////////////////// 测试,输出距离 ///////////////// # m = 0 # for k,v in self._distMap: # m +=1 # print v,"\t", # if (m%7==0): # print #///////////////////////////////////////////////////// if(2==len(vectors[0])): # 二维样本则显示可视化结果 draw_2D_cluster(vectors, result) return result
def cluster(self, vectors, assign_clusters=False, ClusterNum=None, DisType='euc', Stype='mean', trace=False): # stores the merge order #------------------------------------------------- self._distMap.clear() # 每次聚类不同样本之前必须更新 #------------------------------------------------- l = len(vectors) if (0 == l): return [] if ('cos' == DisType): for i in range(l): for j in range(i + 1, l): self._distMap[(i, j)] = cosine_distance( vectors[i], vectors[j]) elif ('euc' == DisType): for i in range(l): for j in range(i + 1, l): self._distMap[(i, j)] = euclidean_distance( vectors[i], vectors[j]) result = VectorSpaceClusterer.cluster(self, vectors, assign_clusters, ClusterNum, Stype, trace) #/////////////////////// 测试,输出距离 ///////////////// # m = 0 # for k,v in self._distMap: # m +=1 # print v,"\t", # if (m%7==0): # print #///////////////////////////////////////////////////// if (2 == len(vectors[0])): # 二维样本则显示可视化结果 draw_2D_cluster(vectors, result) return result
def cluster(self, vectors, assign_clusters=False, DisType='cos',Stype='avg',trace=False): # stores the merge order #------------------------------------------------- self._distMap.clear() # 每次聚类不同样本之前必须更新 #------------------------------------------------- l = len(vectors) if('cos'==DisType): for i in range(l): for j in range(i+1,l): self._distMap[(i,j)] = cosine_distance(vectors[i], vectors[j]) elif('euc'==DisType): for i in range(l): for j in range(i+1,l): self._distMap[(i,j)] = euclidean_distance(vectors[i], vectors[j]) self._dendrogram = Dendrogram( [numpy.array(vector, numpy.float64) for vector in vectors]) result = VectorSpaceClusterer.cluster(self, vectors,assign_clusters, Stype, trace) return result