Ejemplo n.º 1
0

#saving TOP terms per cluster:
order_centroids = km.cluster_centers_.argsort()[:, ::-1]		
terms = feature_names
for i in range(numK):
	for ind in order_centroids[i, :15]:
		clusterList[i].topTerms.append(terms[ind])


#saving post per cluster
counter = 0
for post in postCollection.list:
	postCluster = km.labels_[counter]
	clusterList[postCluster].posts.append(post)
	post.cluster = postCluster
	counter += 1
	
	# for post in postCollection.list:
# 		print(post.cluster)
# 	
# 	for i in range(numK):
# 		print("\n\n\nCluster Num:%d." % i)
# 		for post in postCollection.getClusterElements(i):
# 			print(post.text)
if opts.showCluster:	
	for cluster in 	clusterList:
		print("%s\n\n\nCluster Num:%s%d.%s" % (RED,BOLD,cluster.id,ENDC))
		topTermString = ""
		for topTerm in cluster.topTerms:
			topTermString += topTerm + "  "