Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Generate a Word Cloud | Tweet Sentiment Analysis
Tweet Sentiment Analysis

book
Generate a Word Cloud

A word cloud (also known as a tag cloud) is a visual representation of the most frequently used words in a piece of text. The size of each word in the cloud corresponds to its frequency of use, with the most frequently used words appearing larger and more prominent than less frequently used words.

Word clouds are often used to quickly and easily identify the most important or relevant words in a piece of text, such as a document, a webpage, or a set of social media posts. They can be used in a variety of applications, such as text mining, content analysis, and social media monitoring.

Tarefa

Swipe to start coding

  1. Import WordCloud, STOPWORDS, ImageColorGenerator from wordcloud.
  2. Select only the "neutral" tweets (the "sentiment" column).
  3. Create a plot using the plot_wordcloud() function.

Solução

from PIL import Image
import numpy as np
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator

def plot_wordcloud(text, mask=None, max_words=200, max_font_size=100, figure_size=(24.0,16.0), color = 'white',
title = None, title_size=40, image_color=False):
stopwords = set(STOPWORDS)
more_stopwords = {"u", "im"}
stopwords = stopwords.union(more_stopwords)

wordcloud = WordCloud(background_color=color,
stopwords = stopwords,
max_words = max_words,
max_font_size = max_font_size,
random_state = 42,
width=600,
height=300,
mask = mask)
wordcloud.generate(str(text))

plt.figure(figsize=figure_size)
if image_color:
image_colors = ImageColorGenerator(mask);
plt.imshow(wordcloud.recolor(color_func=image_colors), interpolation="bilinear");
plt.title(title, fontdict={"size": title_size,
"verticalalignment":"bottom"})
else:
plt.imshow(wordcloud);
plt.title(title, fontdict={"size": title_size, "color": "black",
"verticalalignment": "bottom"})
plt.axis("off");
plt.tight_layout()

Neutral_sent = data[data["sentiment"]=="neutral"]
plot_wordcloud(Neutral_sent.text,color='white',max_font_size=100,title_size=30,
title="WordCloud of Neutral Tweets")

Mark tasks as Completed
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 9
AVAILABLE TO ULTIMATE ONLY
some-alt