cleanUrl: 'articles/politicTend'
βμ€λ¦½μ μΈ μ λͺ©μ μ€μκ° λΌμ΄λΈ λ΄μ€μμμμλ
μ±λμ μ μΉμ±ν₯μ λ°λΌ λκΈμ μ°¬λ°μ¬λ‘ μ°¨μ΄κ° λλλ¬μ§κ² λνλ κΉ?β
μ΄λ₯Ό μμ보기 μν΄
- μ§λ³΄μ 보μλ‘ κ°κ° λνλλ μλ‘ λ€λ₯Έ μ μΉμ±ν₯μ λ μ±λμ
- μ μΉμ±ν₯ μκ΄μμ΄ μ λ λ€μκ° μμ²νμ βλν΅λ Ή μ·¨μμ λΌμ΄λΈ μμβ λκΈμ
λΉκ΅ν΄λ³΄κΈ°λ‘ νμ΅λλ€.
Β
λκΈ νμ© μ¬λΆ, μ νλΈ μ±λ ꡬλ
μ μ λ° ν΄λΉ μμ μ‘°νμλ₯Ό κΈ°μ€μΌλ‘ μμμ μ μ ν κ²°κ³Ό, μ§λ³΄ μΈλ‘ μ¬λ‘λ JTBC, 보μ μΈλ‘ μ¬λ‘λ μ±λ Aλ₯Ό μ μ νμ¬ μμ λκΈμ ν¬λ‘€λ§νμμ΅λλ€.
Β
Β
1. λκΈ ν¬λ‘€λ§
Β
Β
from selenium import webdriver as wd from bs4 import BeautifulSoup import time from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager #μ μ₯κ²½λ‘ μ€μ s = Service("C:/Users/vip/Downloads/chromedriver_win32/chromedriver.exe") driver = wd.Chrome(service = s) #driver = wd.Chrome(executable_path = "C:/Users/vip/Downloads/chromedriver_win32/chromedriver.exe") time.sleep(2) #μλμ° ν¬κΈ° μ‘°μ driver.maximize_window() #JTBCλ΄μ€ λΌμ΄λΈμμ λ§ν¬ μ μ url = 'https://www.youtube.com/watch?v=ksO9xGYTf1s' driver.get(url) #μ μν νμ΄μ§μ κ°μ₯ μλκΉμ§ μ€ν¬λ‘€νκΈ° last_page_height = driver.execute_script("return document.documentElement.scrollHeight") while True : driver.execute_script("window.scrollTo(0, document.documentElement.scrollHeight);") time.sleep(30.0) new_page_height = driver.execute_script("return document.documentElement.scrollHeight") if new_page_height == last_page_height: break last_page_height = new_page_height #νμ± λ°©λ² μ€μ html_source = driver.page_source soup = BeautifulSoup(html_source, 'lxml') # μ€ν¬λνν μμ μ€μ (λλ€μ, λκΈ, κ³΅κ° μ) userID = soup.select('a#author-text') #λ€λ₯Έ κ²½λ‘..? userID = soup.select('div#header-author > a > span') comment = soup.select('yt-formatted-string#content-text') positive = soup.select('span#vote-count-middle') str_userID = [] str_comment = [] str_positive = [] #μλ―Έμλ κ° μ²λ¦¬ for i in range(len(userID)): str_tmp = str(userID[i].text) str_tmp = str_tmp.replace('\n', '') str_tmp = str_tmp.replace('\t', '') str_tmp = str_tmp.replace(' ', '') str_userID.append(str_tmp) str_tmp = str(comment[i].text) str_tmp = str_tmp.replace('\n', '') str_tmp = str_tmp.replace('\t', '') str_tmp = str_tmp.replace(' ', '') str_comment.append(str_tmp) str_tmp = str(positive[i].text) str_tmp = str_tmp.replace('\n', '') str_tmp = str_tmp.replace('\t', '') str_tmp = str_tmp.replace(' ', '') str_positive.append(str_tmp) #μ²λ¦¬λ λ°μ΄ν° μΆλ ₯ for i in range(len(str_userID)): print(str_userID[i], str_comment[i], str_positive[i]) #λ°μ΄ν°νλ μ λ§λ€κΈ° import pandas as pd pd_data = {"ID":str_userID, "Coment":str_comment, "positive":str_positive} youtube_jtbcnews_pd = pd.DataFrame(pd_data) youtube_jtbcnews_pd youtube_jtbcnews_pd.to_excel("C:/Users/...κ²½λ‘/youtube_jtbcnews_comments.xlsx")
Β
2. ννμ λΆμ
Β
λΆμ©μ΄ μ€μ
λΆμν λκΈμ μ§μ λͺ¨μ보μμΌλ μ΄μ λ λ°μ΄ν°λ₯Ό κ°κ³΅ν΄λ³Ό μ°¨λ‘μ
λλ€. λͺ¨μ λ°μ΄ν°λ₯Ό 무μμ μκ°ννλ€κ° λμ΄μ°κΈ°λ μ λλ‘ λμ΄ μμ§ μμ λκΈμ΄ κ·Έλλ‘ λ€μ΄κ° μ μμΌλκΉμ!
λ¨Όμ , μ°λ¦¬μ λΆμμμ μ°μ§ μμ λ¨μ΄λ₯Ό μ§μ ν΄ λ°μ΄ν°μμ μμ ν΄ μ€ νμκ° μμ΅λλ€. μ΄λ¬ν λ¨μ΄λ€μ λ°λ‘ λΆμ©μ΄λΌκ³ μ§μΉνλλ°, μ°κ΅¬μ λ§μλλ‘ μ§μ ν μ μλ΅λλ€! 보ν΅μ βμ/λ/μ΄/κ°βμ κ°μ μ‘°μ¬λ, β~ν©λλ€β κ°μ μ΄λ―Έ, βμ¬λβ, βμ¬μ€β, βμ΄μ΄μΏ βκ°μ΄ ν° λ»μ΄ μλ λ¨μ΄λ€μ λΆμ©μ΄λ‘ μ§μ νκ³ λ ν©λλ€. 보νΈμ μΌλ‘ μ°μ΄λ νκ΅μ΄ λΆμ©μ΄ μμλ λ€μκ³Ό κ°μ΅λλ€.
Β
μ΄λ² μ€μ΅μμλ βμ€μμ΄ λν΅λ Ή μ·¨μμβμ΄ λμ£Όμ μλ λ§νΌ, μ νμΌ μ λ¨μ΄λ€κ³Ό ν¨κ» λ μ±λμ λκΈμ 곡ν΅μΌλ‘ λ§μ΄ λμ¬ λ§ν βμ€μμ΄β, βλν΅λ Ήβ, βλν΅λ Ήλβ λ±μ λ¨μ΄λ λΆμ©μ΄λ‘ μ€μ νλ΅λλ€! λν, μ νμΌμ λ¬Έμ₯ λΆνΈλ ν¬ν¨λμ§ μμμΌλ, λ°μ΄ν° μκ°νμμ β!βμ κ°μ κΈ°νΈκ° κ°μ₯ ν¬κ² λμ€κΈΈ μνμ§ μλλ€λ©΄ λ¬Έμ₯ λΆνΈλ λ³λλ‘ μΆκ°ν΄μ€μΌκ² μ£ ?
Β
κ·Έλ¬λ©΄ μ΄κ²μ μ΄λ»κ² μ½λλ‘ μ μνλμ?
νμ¬ λΆμ©μ΄κ° txt νμΌλ‘ μ μλμ΄ μμΌλ λμ€μ μ΄κ²μ μ¬μ©νλ €λ©΄ ν λΌμ΄λΈλ¬λ¦¬ μμ 미리 λ£μ΄λ¬μΌ ν©λλ€. κ·Έλ¬κΈ° μν΄μ μ½λλ‘ λ―Έλ¦¬ λΆμ©μ΄λ₯Ό μ μν΄μΌ νλλ°, μ΄λ νμΌμ μ μ΄ν΄λ³΄λ©΄ λ¨μ΄λ§λ€ μ€λ°κΏμ΄ λμ΄ μλ€λ κ±Έ μ μ μμ΅λλ€. μ°λ¦¬λ λΆμ©μ΄κ° μλλ‘ μΆλ ₯λλ ννκ° μλ, 리μ€νΈμ²λΌ μμΌλ‘ λ°°μ΄λμ΄ μλ ννλ₯Ό μνλ―λ‘ μ΄ λͺ©μ μ λ§μΆμ΄ μ½λλ₯Ό ꡬνν΄μ€λλ€.
Β
with open('stop_words.txt', 'r') as file: data = file.read().replace('\n', ' ') with open('stop_word2.txt', 'r') as file: content = file.read().replace('\n', ' ') stop_words = " ".join((data, content 'μ€μμ΄', 'λν΅λ Ή', 'λν΅λ Ήλ', 'λνλ―Όκ΅', 'μ·¨μμ', 'μ·¨μ', 'λν΅λ Ήμ΄', '~', 'λλΌ', 'κ΅λ―Ό', '?!', '.', '!', ':', '...', '?', ',', 'β₯', '?)..', ')'))
Β
μ΄ λ¨κ³λ₯Ό ν΅ν΄ stop_words.txt, stop_word2.txt, κ·Έλ¦¬κ³ μ°λ¦¬κ° μΆκ°λ‘ μ§μ ν λ¨μ΄λ€μ΄ stop_wordsλΌλ μ΄λ¦ μλ λ€μ΄κ° μκ² λ©λλ€.
Β
ννμ λΆμ
본격μ μΌλ‘ λ°μ΄ν°λ₯Ό μ μνκΈ° μν΄μλ κΌ μμμΌ ν κ°λ
μ΄ μμ΅λλ€: λ°λ‘ ννμμ
λλ€.
ννμ(morpheme): μλ―Έλ₯Ό κ°μ§λ κ°μ₯ μμ λ§μ λ¨μ
μλ₯Ό λ€μ΄, βλλ λ₯λ€μ΄λΈ μν°ν΄μ μ½κ³ μλ€.βλΌλ λ¬Έμ₯μ΄ μλ€κ³ ν©μλ€. μ¬κΈ°μ λ¨μ΄λ 무μμΌκΉμ? βλβ, βλβ, βλ₯λ€μ΄λΈβ, βμν°ν΄β, βμβ, βμ½κ³ β, βμλ€βλ‘ λλ μ μκ² μ£ . λ³΄ν΅ λ¨μ΄λ λμ΄μ°κΈ°λ‘ λλ μ£Όκ³ , μ‘°μ¬λ λ€λ₯Έ λ¨μ΄μ λΆμ΄ μλλΌλ μμΈμ μΌλ‘ λΆλ¦¬μ±μ μΈμ νμ¬ λ¨μ΄ μ·¨κΈμ ν΄μ£ΌλκΉμ.
κ·Έλ λ€λ©΄ ννμλ 무μμΌκΉμ? βμλ―Έβλ₯Ό κ°μ§λ€λ κ²μ΄ ꡬ체μ μΌλ‘ μ΄λ€ λ»μΌκΉμ?
κ°λ¨ν©λλ€. βμ½κ³ μλ€βλ λμ¬κ΅¬λ§ μ΄ν΄λ³Όκ²μ. κ·Έλ¬λ©΄ μ°λ¦¬λ μμ°μ€λ½κ² μ΄ κ΅¬λ₯Ό βμ½-β, β-κ³ β, βμ-β, β-λ€βλ‘ μ’ λ μκ² μͺΌκ°€ μ μλ€λ κ±Έ μκ² λ©λλ€. βμ½κ³ βλΌλ λ¨μ΄λ βμ½μΌλ©°β, βμ°κ³ β λ± λ€μν λ¨μ΄λ‘ νμ©λ μ μμΌλ, βμ½-βκ³Ό β-κ³ βλΌλ κΈμλ κΌ λΆμ΄ μμ νμκ° μμ΅λλ€. λ κΈμκ° κ°μ§κ³ μλ μλ―Έλ λ€λ₯΄κ³ μ. μ°λ¦¬λ μ΄λ° λ¨μλ₯Ό ννμλΌκ³ λΆλ¦
λλ€.
μΈλΆμ μΌλ‘λ, ννμλ μ΄λ€ μλ―Έλ₯Ό κ°μ§λμ§μ λ°λΌ μ€μ§ ννμμ νμ ννμλ‘ λλ©λλ€. μ΄ μ¬λ‘μμλ νλμ μ§μΉνλ βμ½-βκ³Ό βμ-βμ΄ μ€μ§ ννμ, μ΄λ―Έμ ν΄λΉνλ β-κ³ β, β-λ€βκ° βνμ ννμβμ μνλ΅λλ€. μ립μ±μ λ°λΌ μ립 ννμμ μμ‘΄ ννμλ‘ λλκΈ°λ νλλ°, μ°λ¦¬λ λ°μ΄ν°μ λ΄μ©μ μ΄ν΄λ³΄κ³ μΆμΌλ ννμκ° κ°μ§λ μλ―Έμ μ§μ€νλλ‘ ν©μλ€!
Β
κ·Έλμ,
μ°λ¦¬κ° μ§κΈ νκ³ μ νλ κ²μ λͺ¨μ λκΈμ βμ€μ§ ννμβλ‘ λΆμνλ μΌμ
λλ€.
μ€μ§ ννμμ νμ ννμ μ€ μ°λ¦¬κ° λ κ΄μ¬μ΄ μλ 건 무μμΌκΉμ? λΉμ°ν, μ€μ§ ννμμ
λλ€. λ§μΌ μ΄λ€ κ΅¬κ° β-κ³ -λ€βλ μμΌλ‘ νμ ννμλ§ λͺ¨μ μ ν μλ€λ©΄, βμ½- μ-βμ΄λΌλ μ€μ§ ννμ ꡬμ λ³΄λ€ λ΄μ©μ μκΈ° μ΄λ €μ°λκΉμ. κ·Έλ μ§λ§ μ°λ¦¬κ° λκΈμ ννμ λ¨μλ‘ νλνλ λΆμν μ μμΌλ, νμ΄μ¬ ν¨ν€μ§μ νμ λΉλ¦¬λλ‘ ν©μλ€.
ννμ λΆμμ ν΄μ£Όλ λνμ μΈ ν¨ν€μ§λ nltkλ‘, Natural Language Toolkitμ μ½μμ
λλ€. μ΄ ν¨ν€μ§μμλ word_tokenize ν¨μκ° λ°λ‘ ννμ λΆμμ λμ ν΄μ€ μΉκ΅¬μ
λλ€. μ΄ κ³Όμ μ μ½λλ‘ κ΅¬ννλ κ³Όμ μ λ€μκ³Ό κ°μ΅λλ€.
Β
import nltk nltk.download('punkt') from nltk import word_tokenize JTBCnltk = word_tokenize(JTBC_str) ChAnltk = word_tokenize(ChA_str)
Β
μ΄ κ³Όμ μμ μ°λ¦¬κ° μμ μ μνλ λΆμ©μ΄λ₯Ό μ¨μΌ ν©λλ€. stop_wordsμ λ€μ΄κ° μλ λ¨μ΄λ₯Ό μ μΈν λ°μ΄ν°μλ§ word_tokenizer ν¨μλ₯Ό μ°λΌλ μλ―Έλ‘μ!
Β
JTBC_nltkr = [word for word in JTBCnltk if not word in stop_words] ChA_nltkr = [word for word in ChAnltk if not word in stop_words]
Β
μ΄λ κ² ννμ λΆμλ§ νκ³ λμ΄κ°κΈ°λ μμ¬μ°λ, ν¨ν€μ§κ° λλ ννμ κ°μλ₯Ό μΈ μ£Όλ Counter ν¨ν€μ§λ μ€μΉν΄ κ²°κ³Όλ₯Ό μ΄ν΄λ³Ό μ μμ΅λλ€.
Β
from collections import Counter JTBCnltkc = Counter(JTBC_nltkr) ChAnltkc = Counter(ChA_nltkr) print(JTBCnltkc) print(ChAnltkc)
Β
κ·Έλ°λ°, κ²°κ³Όλ₯Ό 보면 μ΄μν μ μ΄ νλ μμ΅λλ€. μ±λ Aμ λ°μ΄ν°μμ κ°μ₯ λ§μ΄ λ±μ₯ν ννμκ° βλλΌλ₯Όβμ΄λΌκ³ μΆλ ₯λ©λλ€. 무μμ΄ μ΄μνμ§ λμΉ μ±μ
¨λμ?
λ§μμ, βλλΌλ₯Όβμ νλμ ννμκ° μλλλ€! βλλΌβμ βλ₯Όβμ΄λΌλ λ κ°μ ννμλ‘ μ΄λ£¨μ΄μ Έ μμ£ . κ·Έλ¬λ©΄ ν¨ν€μ§κ° λ¨μ΄λ₯Ό μλͺ» λΆμν μ
μΈλ°, μ μ΄λ° κ²°κ³Όκ° (κ·Έκ²λ κ½€ λΉλ²ν!) λμ¬κΉμ?
κ·Έκ²μ λ°λ‘ nltkκ° μμ΄λ₯Ό ν λλ‘ κ°λ°λ ν¨ν€μ§κΈ° λλ¬Έμ
λλ€. μ½κ² λ§νμλ©΄, μ°λ¦¬κ° λΆμνλ €κ³ νλ 건 μμ΄κ° μλ νκ΅μ΄κΈ° λλ¬Έμ nltkμ μ±λ₯μ΄ μ‘°κΈ λ¨μ΄μ§λ€λ κ²μ΄μ£ .
μ΄ μ μ κ°μν΄ κ°λ°λ ν¨ν€μ§κ° λ°λ‘ KoNLPyμ
λλ€. κ΅μ₯ν μ§κ΄μ μΈ μ΄λ¦μ΄μ£ ? κ·ΈλΌ KoNLPyλ₯Ό μ§μ μ¬μ©ν΄λ³΄λλ‘ ν©μλ€. KoNLPyλ μ΄ λ€μ― κ°μ§ ν¨ν€μ§λ₯Ό μ 곡νλλ°, μ΄λ² μ€μ΅μμ μ¬μ©ν κ²μ Mecabμ
λλ€.
Β
pip install konlpy !curl -s https://raw.githubusercontent.com/teddylee777/machine-learning/master/99-Misc/01-Colab/mecab-colab.sh | bash from konlpy.tag import Mecab mecab = Mecab()
Β
Mecab μμλ κΈ°λ³Έμ μΌλ‘ ννμλ₯Ό λΆμν΄μ£Όλ ν¨μ mecab.morphsμ, λͺ
μ¬λ§ λΆμν΄μ£Όλ ν¨μ mecab.nouns λ±μ΄ μμ΅λλ€. μ, κ·ΈλΌ μ¬κΈ°μ νλ λ μκ°ν΄λ΄
μλ€. λ°μ΄ν°λ₯Ό ννμ λ¨μλ‘ μͺΌκ°λ κ²κ³Ό λͺ
μ¬ λ¨μλ‘ μͺΌκ°λ κ², λ μ€ λ¬΄μμ΄ λ°μ΄ν°μ λ΄μ©μ λ μ ννν΄μ€κΉμ?
λ¨μ° λͺ
μ¬μ
λλ€. ννμ μμλ μμ μκΈ°ν νμ ννμλ ν¬ν¨λΌ μμΌλ λͺ
μ¬μ μλ―Έκ° μ’ λ μ§μ μ μΌ κ²μ
λλ€. κ·Έλ μ§λ§, μμ λμΌλ‘ λ μ°¨μ΄λ₯Ό νμΈν΄λ³΄λ κ² κ°μ₯ νΈνκ² μ£ ? μ£Όμ΄μ§ λ°μ΄ν°μ ννμ λΆμκ³Ό λͺ
μ¬ λΆμμ λͺ¨λ ν΄μ λΉκ΅ν΄λ³΄κ² μ΅λλ€.
Β
ννμ λ¨μ λΆμ
JTBCM = mecab.morphs(JTBC_str) ChAM = mecab.morphs(ChA_str) JTBC_r = [word for word in JTBCM if not word in stop_words] ChA_r = [word for word in ChAM if not word in stop_words]
Β
λͺ
μ¬ λ¨μ λΆμ
JTBC_nouns = mecab.nouns(JTBC_str) ChA_nouns = mecab.nouns(ChA_str) JTBC_nresult = [word for word in JTBC_nouns if not word in stop_words] ChA_nresult = [word for word in ChA_nouns if not word in stop_words]
Β
κΈ°λ³Έμ μΈ λ°μ΄ν° μ μ²λ¦¬λ λλ¬κ³ , μ΄μ μ°λ¦¬κ° κ°κ³΅ν λ°μ΄ν°λ₯Ό λμΌλ‘ νμΈν΄λ³Ό μ°¨λ‘μ
λλ€!
3. λ°μ΄ν° μκ°ν (μλν΄λΌμ°λ)
Β
ννμ λΆμμ λ§μΉ νμλ μκ°ν μμ
μ μ§ννμμ΅λλ€. λΆμ κ²°κ³Όλ₯Ό λΆλͺ
ν λνλ΄κΈ°μ μλ ν΄λΌμ°λκ° μ ν©ν κ²μ΄λΌ νλ¨νμ¬ μλ ν΄λΌμ°λλ‘ λ°μ΄ν°λ₯Ό μκ°ννμμ΅λλ€.
μλ ν΄λΌμ°λ(Wordcloud) : ν
μ€νΈ λ΄ λ¨μ΄κ° μΈκΈλ μμΌλ‘ ν¬κΈ°λ₯Ό λ€λ₯΄κ² νμ¬ λ¨μ΄μ μ€μλλ₯Ό μκ°ννλ λ°©λ²
Β
1) νμν λΌμ΄λΈλ¬λ¦¬ μ€μΉ
Β
μλν΄λΌμ°λλ₯Ό μμ±νκΈ°μ μμμ νμν λΌμ΄λΈλ¬λ¦¬λ₯Ό μ€μΉν΄μ€ κ²μ
λλ€.
μ°λ¦¬κ° μ€λ μ¬μ©ν λΌμ΄λΈλ¬λ¦¬λ λ°λ‘ Matplotlibμ
λλ€. matplotlib.pyplot λͺ¨λμ MATLABκ³Ό λΉμ·νκ² λͺ
λ Ήμ΄ μ€νμΌλ‘ λμνλ ν¨μμ λͺ¨μμ
λλ€. ν΄λΉ λͺ¨λμ κ°κ°μ ν¨μλ₯Ό μ¬μ©νμ¬ κ°νΈνκ² κ·Έλνλ₯Ό λ§λ€κ³ λ³νλ₯Ό μ€ μ μμ΅λλ€!
Pillow λͺ¨λμ νμ΄μ¬ μ΄λ―Έμ§ μ²λ¦¬λ₯Ό λ΄λΉνλ λͺ¨λμ
λλ€. λ€μν μ΄λ―Έμ§ νμΌ νμμ μ§μνλ©°, κ°λ ₯ν μ΄λ―Έμ§ μ²λ¦¬μ κ·Έλν½ κΈ°λ₯μ μ 곡νλ μ΄λ―Έμ§ νλ‘μΈμ± λΌμ΄λΈλ¬λ¦¬μ
λλ€.
Β
from wordcloud import WordCloud # matplotlib.pyplot λͺ¨λμ κ°κ° ν¨μλ₯Ό μ¬μ©νμ¬ κ°νΈνκ² κ·Έλνλ₯Ό λ§λ€ μ μλ€. import matplotlib.pyplot as plt # collections λͺ¨λμ counter ν΄λμ€λ μ£Όμ΄μ§ λ¨μ΄μ ν¬ν¨λ κ° κΈμμ μλ₯Ό μΈμ΄μ€λ€. from collections import Counter from konlpy.tag import Okt from PIL import Image import numpy as np
Β
2) mecab.nounsλ₯Ό νμ©ν JTBC λκΈ μλν΄λΌμ°λ μμ±νκΈ°
Β
Mecab λ΄μμ λͺ
μ¬λ§ λΆμν΄μ£Όλ mecab.nouns ν¨μλ₯Ό μ¬μ©νμ¬ JTBC λκΈ λ°μ΄ν°λ₯Ό λͺ
μ¬ λ¨μλ‘ μͺΌκ°κ³ , μ΄λ₯Ό μλν΄λΌμ°λλ‘ μκ°ν ν΄μ£Όμμ΅λλ€.
scale, max_font_size μ΅μ
μΌλ‘ λ¨μ΄μ ν°νΈ ν¬κΈ°λ₯Ό μ€μ ν΄μ£Όμκ³ , background_color μ΅μ
μ βwhiteβλ‘ μ§μ ν¨μ λ°λΌ λ°°κ²½ μμμ νμμμΌλ‘ μ€μ νμμ΅λλ€. width, height μ΅μ
μ ν΅ν΄ μλν΄λΌμ°λ ν¬κΈ°λ₯Ό μ€μ νμΌλ©°, random_state μΈμλ₯Ό μ§μ ν΄μ£Όμ΄ μλν΄λΌμ°λμ μ€νμΌμ κ³ μ νμμ΅λλ€.
Β
wordcloud = WordCloud(font_path='/content/NanumGothic.ttf', scale=2.0, max_font_size=250, background_color ='white', colormap='autumn', width = 700, height = 700, random_state = 43).generate_from_frequencies(JTBC_nouncount) plt.figure(figsize = (6, 6)) # μ΅μ’ μλ ν΄λΌμ°λ μ¬μ΄μ¦ μ§μ plt.imshow(wordcloud) plt.title("Word Frequency", size = 13) plt.axis('off') # κ·Έλν μΆ μ κ±° plt.show()
Β
3) mecab.nounsλ₯Ό νμ©ν Channel.A λκΈ μλν΄λΌμ°λ μμ±νκΈ°
Β
κ°μ λ°©λ²μΌλ‘ Channel.A λκΈ λ°μ΄ν°λ₯Ό μλν΄λΌμ°λλ‘ μκ°ν ν΄μ£Όμμ΅λλ€. μ΅μ
μ κΈ°λ³Έμ μΈ μ€μ μ μμ JTBC λκΈμ μκ°νν κ²κ³Ό λμΌνκ² μ§μ νμμ΅λλ€.
Β
wordcloud = WordCloud(font_path='/content/NanumGothic.ttf', scale=2.0, max_font_size=250, background_color ='white', colormap='autumn', width = 700, height = 700, random_state = 43).generate_from_frequencies(ChA_nouncount) plt.figure(figsize = (6, 6)) # μ΅μ’ μλ ν΄λΌμ°λ μ¬μ΄μ¦ μ§μ plt.imshow(wordcloud) plt.title("Word Frequency", size = 13) plt.axis('off') # κ·Έλν μΆ μ κ±° plt.show()
Β
4) Mecab.morphsλ₯Ό νμ©ν JTBC λκΈ μλν΄λΌμ°λ μμ±νκΈ°
Β
μ΄μ λ Mecab λ΄μμ λ°μ΄ν°λ₯Ό ννμ λ¨μλ‘ μͺΌκ°λ mecab.morphs ν¨μλ₯Ό μ¬μ©νμ¬ JTBC λκΈ λ°μ΄ν°λ₯Ό μλν΄λΌμ°λλ‘ μκ°ν ν΄λ³΄κ² μ΅λλ€.
Β
wordcloud = WordCloud(font_path='/content/NanumGothic.ttf', scale=2.0, max_font_size=250, background_color ='white', colormap='autumn', width = 700, height = 700, random_state = 43).generate_from_frequencies(JTBCMc) plt.figure(figsize = (6, 6)) # μ΅μ’ μλ ν΄λΌμ°λ μ¬μ΄μ¦ μ§μ plt.imshow(wordcloud) plt.title("Word Frequency", size = 13) plt.axis('off') # κ·Έλν μΆ μ κ±° plt.show()
Β
5) Mecab.morphsλ₯Ό νμ©ν Channel.A λκΈ μλν΄λΌμ°λ μμ±νκΈ°
Β
κ°μ λ°©λ²μΌλ‘ Channel.A λκΈ λ°μ΄ν° μμ ννμ λ¨μλ‘ μͺΌκ°μ΄ μλν΄λΌμ°λλ₯Ό μμ±ν©λλ€!
Β
wordcloud = WordCloud(font_path='/content/NanumGothic.ttf', scale=2.0, max_font_size=250, background_color ='white', colormap='autumn', width = 700, height = 700, random_state = 43).generate_from_frequencies(ChAc) plt.figure(figsize = (6, 6)) # μ΅μ’ μλ ν΄λΌμ°λ μ¬μ΄μ¦ μ§μ plt.imshow(wordcloud) plt.title("Word Frequency", size = 13) plt.axis('off') # κ·Έλν μΆ μ κ±° plt.show()
Β
6.) nltkλ₯Ό νμ©ν JTBC, Channel.A λκΈ μλν΄λΌμ°λ μμ±νκΈ°
Β
μ΄λ²μλ nltk ν¨ν€μ§λ₯Ό μ΄μ©νμ¬ JTBCμ Channel.A λκΈ μλν΄λΌμ°λλ₯Ό μμ±ν΄λ³΄κ² μ΅λλ€.
Β
##JTBC λκΈ μλν΄λΌμ°λ μμ±νκΈ° wordcloud = WordCloud(font_path='/content/NanumGothic.ttf', scale=2.0, max_font_size=250, background_color ='white', colormap='autumn', width = 700, height = 700, random_state = 43).generate_from_frequencies(JTBCnltkc) plt.figure(figsize = (6, 6)) # μ΅μ’ μλ ν΄λΌμ°λ μ¬μ΄μ¦ μ§μ plt.imshow(wordcloud) plt.title("Word Frequency", size = 13) plt.axis('off') # κ·Έλν μΆ μ κ±° plt.show() ##Channel A λκΈ μλν΄λΌμ°λ μμ±νκΈ° wordcloud = WordCloud(font_path='/content/NanumGothic.ttf', scale=2.0, max_font_size=250, background_color ='white', colormap='autumn', width = 700, height = 700, random_state = 43).generate_from_frequencies(ChAnltkc) plt.figure(figsize = (6, 6)) # μ΅μ’ μλ ν΄λΌμ°λ μ¬μ΄μ¦ μ§μ plt.imshow(wordcloud) plt.title("Word Frequency", size = 13) plt.axis('off') # κ·Έλν μΆ μ κ±° plt.show()
Β
λ μ¬μ§ λͺ¨λ 곡ν΅μ μΌλ‘ β5λ
λμβμμ β5λ
βκ³Ό βλμβμ΄λ βλλΌλ₯Όβμμ βλλΌβλ βλ₯Όβμ ννμλ₯Ό μ λλ‘ λΆμνμ§ λͺ»ν λͺ¨μ΅μ νμΈνμ€ μ μμ΅λλ€. μ΄λ μκ°μ μΌλ‘ νμ°ν μ°¨μ΄λ λλλ¬μ§μ§ μμΌλ©°, μΈλͺ
μ κΈ°μ€μΌλ‘ νμ λλ μμͺ½ λͺ¨λ βκΉκ±΄ν¬"κ° κ³΅ν΅μΌλ‘ λ±μ₯νλ€λ μ μ μ μ μμ΅λλ€.
Β
4. κ²°κ³Ό ν΄μ
Β
λ€μκ³Ό κ°μ΄ ν΄μν μ μμ΅λλ€.
- μ νλΈ μ€μκ° λΌμ΄λΈ μμμ μκ°λ³΄λ€ μ§λ³΄λ 보μ μ§μμ μΆ©μ±λλ₯Ό λ°μνμ§λ μλλ€
- λλΆλΆ λκΈ λ°μ΄ν°λ€μ μ λ°μ μΈ λ§₯λ½μ λΉμ·νλ νΉμ ν€μλμ μΈκΈλμμ μΈλΆμ μΈ μ°¨μ΄κ° μ‘΄μ¬νλ€
Β