반응형
WordCloud Visualizing
ex)
스팸 이메일에는 어떤 단어들이 많이 들어있는지
Visualizing

from wordcloud import wordcloud, STOPWORDS
워드 클라우드를 사용하려면
판다스의 스팸컬럼에 저장된 문자열을, 리스트로 먼저 받아오고
리스트에 있는 문자열을 다 합쳐서 하나의 문자열로 만들어준다.
spam_email_list = spam['text'].tolist()
spam_email = ''.join(spam_email_list)
spam_email

my_stopwords = STOPWORDS
my_stopwords.add('subject')
from PIL import Image
img = Image.open('as.png')
img

틀을잡아줄 이미지는 배경이 투명인 png파일이어야 한다.
img_mask = np.array(img)
wc = wordcloud.WordCloud(background_color='white', mask= img_mask, stopwords=my_stopwords)
wc.generate(spam_email)

plt.figure(figsize = (10, 6))
plt.imshow(wc)
plt.axis('off')
plt.show()

반응형
'Machine Learning' 카테고리의 다른 글
| Machine Learning - error_bad_line & EDA & datetime64 & dt속성사용법 (0) | 2022.05.11 |
|---|---|
| Machine Learning - FaceBook Prophet Library (0) | 2022.05.11 |
| Machine Learning - CountVectorizer (analyzer) (0) | 2022.05.11 |
| Machine Learning - 구두점 & STOPWORDS(불용어) & Pipe Lining (0) | 2022.05.11 |
| Machine Learning - GridSearchCV (0) | 2022.05.09 |