def visualize_topics(H):
'''
INPUT
- H matrix of topics
OUTPUT
- a scatter plot of the relative location of the different topics
from each other in a flattened space using PCA
- color_list - the list of colors to be used in the next
visualizations of the tweets
Returns the color list
'''
mds = MDS(n_jobs=-1)
# pca = PCA(n_components=2)
# hflat = pca.fit_transform(H)
hflat = mds.fit_transform(H)
# colors = cm.rainbow(hflat.shape[0]-1)
colors = cycle(["r", "b", "g", "c", "m", "y", "k", "w"])
color_list = []
for i, row in enumerate(hflat):
color = next(colors)
plt.scatter(row[0], row[1],
label='topic number {}'.format(i+1), color=color)
color_list.append(color)
plt.legend(loc='best')
plt.show()
return color_list, mds
评论列表
文章目录