w2_wordcloud - steelbear/HMG_Softeer_DE GitHub Wiki
Word cloud
Word cloud๋ ๋จ์ด๋ค์ ๊ตฌ๋ฆ์ฒ๋ผ ๊ตฐ์ง์ ์ด๋ฃจ๋ฏ ๋ฐฐ์นํ ์๊ฐ ์๋ฃ๋ฅผ ๋งํ๋ค. ๋จ์ด์ ํฌ๊ธฐ์ ์์ ํตํด ๊ฐ ๋จ์ด๋ณ์ ์๋์ ์ธ ํฌ๊ธฐ๋ ๋น์จ์ ๋ํ๋ธ๋ค. ์์ ๊ทธ๋ฆผ์ ๊ธ์ ์ /๋ถ์ ์ tweet๋ค์ ๋ชจ์ผ๊ณ ๋จ์ด ๋น๋๋ฅผ ํฐํธ ํฌ๊ธฐ๋ก ๋ํ๋ธ Word Cloud๋ค. ์ด๋ฅผ ํตํด ๊ฐ ๊ธ์ ์ ๋๋ ๋ถ์ ์ tweet์์ ์ด๋ค ๋จ์ด๊ฐ ๋ง์ด ๋์ค๋์ง ํ๋์ ์ ์ ์๋ค.
wordcloud
Word cloud๋ฅผ ์์ฝ๊ฒ ๊ทธ๋ฆด ์ ์๋๋ก ๋์์ฃผ๋ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค.
pip install wordcloud
- Github Repository
- Official Documentation
- ๊ฐ๋จํ ์ฌ์ฉ๋ฒ ์ ๋๋ ์ ์ ์์ผ๋, ๊ทธ๋ฆฌ ์์ธํ๊ฒ ๋์ค์ง ์๋๋ค.
์ฝ๋
import matplotlib.pyplot as plt
from wordcloud import WordCloud
# WordCloud ์์ฑ์ ์ธ์๊ฐ์ผ๋ก ์ด๋ฏธ์ง ํฌ๊ธฐ๋ ๋ถ์ฉ์ด ๋ฑ ๋ค์ํ ์ต์
์ ์ถ๊ฐํ ์ ์๋ค
wc = WordCloud()
plt.imshow(wc.generate(text)) # text: str
# WordCloud๊ฐ ๋ถ์ฉ์ด ์ ๊ฑฐ๋ ํ ํฐํ ๋ฑ์ ์ค์ค๋ก ํ๊ธฐ ๋๋ฌธ์
# text์ ์ ์ฒ๋ฆฌ๋ฅผ ํ์ง ์์๋ ๋๋ค.
# ์ด๋ ์ฒ๋ฆฌ๋ ๋จ์ด ๋น๋ ์๊ฐ ๊ฐ์ฒด์ ์ ์ฅ๋๋ค
wc.to_file('wordcloud.png') # ์ด๋ฏธ์ง ํ์ผ ์ ์ฅ
word_freq = wc.process_text(text) # text ๋น๋์ ๊ณ์ฐ + ํ
์คํธ ์ ์ฒ๋ฆฌ(๋ถ์ฉ์ด ์ ๊ฑฐ, ๋ณต์ํ ๋ช
์ฌ ๋จ์ํ ๋ฑ)
plt.imshow(wc.generate_from_frequencies(word_freq)) # word_freq: dict, collections.Counter
# ๋น๋์๋ก word cloud ๊ทธ๋ฆฌ๊ธฐ