트윗의 토픽 모델링

R로 소셜 미디어 데이터 분석하기

Vivek Vijayaraghavan

Data Science Coach

강의 개요

  • 토픽 모델링의 기본
  • 문서-단어 행렬(DTM) 생성
  • DTM으로 토픽 모델 구축
R로 소셜 미디어 데이터 분석하기

토픽과 문서

토픽 정의와 예시

R로 소셜 미디어 데이터 분석하기

토픽과 문서

문서 정의와 예시

R로 소셜 미디어 데이터 분석하기

토픽 모델링

  • 토픽을 자동으로 발견하는 작업
  • 대규모 데이터셋에서 핵심 논의 주제 추출
  • 방대한 정보를 토픽으로 빠르게 요약
R로 소셜 미디어 데이터 분석하기

LDA 작동 방식

  • 토픽 모델링을 위한 잠재 디리클레 할당(LDA) 알고리즘

LDA 작동 방식

R로 소셜 미디어 데이터 분석하기

LDA 작동 방식

LDA 작동 방식

R로 소셜 미디어 데이터 분석하기

LDA 작동 방식

LDA 작동 방식

R로 소셜 미디어 데이터 분석하기

문서-단어 행렬(DTM)

  • 문서-단어 행렬 만들기
  • DTM은 말뭉치의 행렬 표현입니다
  • 문서는 행, 단어/용어는 열입니다

문서-단어 행렬(DTM)

R로 소셜 미디어 데이터 분석하기

문서-단어 행렬 생성

# Create a document term matrix
dtm <- DocumentTermMatrix(twt_corpus_refined)
R로 소셜 미디어 데이터 분석하기

문서-단어 행렬 생성

# Inspect the DTM
inspect(dtm)
R로 소셜 미디어 데이터 분석하기

문서-단어 행렬 생성

<<DocumentTermMatrix (documents: 1000, terms: 5079)>>
Non-/sparse entries: 12862/5066138
Sparsity           : 100%
Maximal term length: 29
Weighting          : term frequency (tf)
Sample             :
     Terms
Docs    california child diabetes fat food health people ranks rates weight
  131          0     0        0   0    0      0      0     0     0      0
  161          0     0        0   2    0      0      0     0     0      1
  295          0     0        0   0    1      0      1     0     0      0
  418          0     0        0   0    0      0      0     0     1      0
  604          0     0        1   0    0      1      0     0     0      0
R로 소셜 미디어 데이터 분석하기

DTM 준비

  • 행 합이 0보다 큰 행만 남기도록 DTM 필터링
# Find the sum of word counts in each Document 
rowTotals <- apply(dtm , 1, sum)
# Select rows from DTM with row totals greater than zero
tweet_dtm_new <- dtm[rowTotals> 0, ]
R로 소셜 미디어 데이터 분석하기

토픽 모델 구축

  • LDA() 함수로 토픽 모델 생성
# Build the topic model
library(topicmodels)
lda_5 <- LDA(tweet_dtm_new, k = 5)
R로 소셜 미디어 데이터 분석하기

토픽 모델 구축

  • 트윗 말뭉치에서 5개 토픽 추출
# View top 10 terms in the topic model
top_10terms <- terms(lda_5,10)
top_10terms
R로 소셜 미디어 데이터 분석하기

상위 10개 용어 보기

     Topic 1        Topic 2        Topic 3     Topic 4      Topic 5   
 [1,] "disease"      "people"       "black"     "child"      "weight"  
 [2,] "health"       "health"       "fat"       "rates"      "diet"    
 [3,] "cancer"       "diabetes"     "trump"     "ranks"      "food"    
 [4,] "meghanmccain" "overweight"   "childhood" "california" "diabetes"
 [5,] "realcandaceo" "fat"          "health"    "fat"        "health"  
 [6,] "food"         "meghanmccain" "professor" "eat"        "bmi"     
 [7,] "risk"         "realcandaceo" "gender"    "people"     "problem" 
 [8,] "heart"        "body"         "studies"   "epidemic"   "eating"  
 [9,] "weight"       "weight"       "healthy"   "health"     "disease" 
[10,] "diabetes"     "obese"        "problem"   "healthy"    "family"
  • 비만 관리 프로그램은 핵심 토픽을 중심으로 주제를 구성할 수 있습니다
R로 소셜 미디어 데이터 분석하기

연습해 봅시다!

R로 소셜 미디어 데이터 분석하기

Preparing Video For Download...