March 2020
Beginner to intermediate
352 pages
8h 40m
English
In order to see the top few keywords that belong to each cluster, we need to create a function that provides us with the top 50 words from each of the clusters and plot the word cloud.
Check the function, as follows:
from wordcloud import WordCloud fig, ax = plt.subplots(4, sharex=True, figsize=(15,10*4))plt.rcParams["axes.grid"] = Falsedef high_frequency_keywords(data, clusters, labels, n_terms): df = pd.DataFrame(data.todense()).groupby(clusters).mean() for i,r in df.iterrows(): words = ','.join([labels[t] for t in np.argsort(r)[-n_terms:]]) print('Cluster {} \n'.format(i)) print(words) wordcloud = WordCloud(max_font_size=40, collocations=False, colormap = 'Reds', background_color = 'white').generate(words) ax[i].imshow(wordcloud, ...Read now
Unlock full access