트윗 필터링

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

Vivek Vijayaraghavan

Data Science Coach

학습 개요

  • 트윗 구성요소로 필터링
    • 원본 트윗 추출
    • 트윗 언어
    • 리트윗·즐겨찾기 최소 수 기준 인기 트윗
R로 소셜 미디어 데이터 분석하기

원본 트윗 필터링

  • 원본 트윗은 사용자가 직접 올린 게시물입니다
  • 리트윗, 인용, 답글이 아님
  • 원본 트윗은 중복 콘텐츠를 줄입니다
  • 사용자 참여 유지에 도움이 됩니다
R로 소셜 미디어 데이터 분석하기

원본 트윗 필터링

  • 원본 트윗 추출에는 -filter 사용
  • -filter:retweets는 모든 리트윗 제외
  • -filter:quote는 인용 트윗 제외
  • -filter:replies는 답글형 트윗 제외
R로 소셜 미디어 데이터 분석하기

필터 없이 트윗 추출

  • "digital marketing" 트윗을 필터 없이 추출
# "digital marketing" 관련 트윗 100개 추출
tweets_all <- search_tweets("digital marketing", n = 100)
R로 소셜 미디어 데이터 분석하기

필터 없이 트윗 추출

  • reply_to_screen_name, is_quote, is_retweet 열의 값 개수 확인
# 답글 수 확인
library(plyr)
count(tweets_all$reply_to_screen_name)
x               freq
<fct>          <int>
blairaasmith      2            
javiergosende     1            
juanburgos        1            
WhutTheHale       2            
NA               94
R로 소셜 미디어 데이터 분석하기

필터 없이 트윗 추출

# 인용 트윗 수 확인
count(tweets_all$is_quote)
x        freq
<lgl>    <int>
FALSE     98            
TRUE       2
R로 소셜 미디어 데이터 분석하기

필터 없이 트윗 추출

# 리트윗 수 확인
count(tweets_all$is_retweet)
x         freq
<lgl>    <int>
FALSE      61            
TRUE       39
R로 소셜 미디어 데이터 분석하기

리트윗·인용·답글 제외

  • -filter를 적용해 "digital marketing" 트윗 추출
# '-filter' 적용
tweets_org <- search_tweets("digital marketing 
                            -filter:retweets 
                            -filter:quote 
                            -filter:replies", 
                            n = 100)
R로 소셜 미디어 데이터 분석하기

리트윗·인용·답글 제외

  • 답글, 인용, 리트윗이 제외되었는지 확인
# 답글 수 확인
library(plyr)
count(tweets_org$reply_to_screen_name)
x         freq
<lgl>    <int>
NA         100
R로 소셜 미디어 데이터 분석하기

리트윗·인용·답글 제외

# 인용 트윗 수 확인
library(plyr)
count(tweets_org$is_quote)

x         freq
<lgl>    <int>
FALSE     100
# 리트윗 수 확인
library(plyr)
count(tweets_org$is_retweet)
x         freq
<lgl>    <int>
FALSE     100
R로 소셜 미디어 데이터 분석하기

언어로 트윗 필터링

  • lang는 언어 기준으로 트윗을 필터링
  • 지정 언어의 트윗만 매칭

일부 언어의 트위터 언어 코드

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

언어로 트윗 필터링

# 스페인어 트윗 필터링 및 추출
tweets_lang <- search_tweets("brand marketing", lang = "es")
R로 소셜 미디어 데이터 분석하기

언어로 트윗 필터링

View(tweets_lang)

스페인어로 추출된 트윗

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

언어로 트윗 필터링

head(tweets_lang$lang)
[1] "es" "es" "es" "es" "es" "es"
R로 소셜 미디어 데이터 분석하기

리트윗·즐겨찾기 수로 필터링

  • min_faves: 즐겨찾기 최소 수 기준 필터
  • min_retweets: 리트윗 최소 수 기준 필터
  • 두 조건 모두 확인하려면 AND 사용
R로 소셜 미디어 데이터 분석하기

리트윗·즐겨찾기 수로 필터링

# 즐겨찾기·리트윗 최소 100개 트윗 추출 
tweets_pop <- search_tweets("bitcoin min_faves:100 AND
                            min_retweets:100")
R로 소셜 미디어 데이터 분석하기

리트윗·즐겨찾기 수로 필터링

# 리트윗·즐겨찾기 수 확인용 데이터 프레임 생성
counts <- tweets_pop[c("retweet_count", "favorite_count")]
head(counts)
retweet_count    favorite_count
    <int>              <int>
1    162                833
2    141                894    
3    164                1128
4    395                1346    
5    475                2271
6    270                1654
R로 소셜 미디어 데이터 분석하기

리트윗·즐겨찾기 수로 필터링

# 트윗 보기
head(tweets_pop$text)
text    
<chr>
1    As we continue to build the Bakkt Bitcoin Futures contract, we reached a
2    BREAKING: The United States is considering entering into a "currency pact"
3    REMINDER: The Bitcoin ETF will eventually get approved.\n\nNot a question
4    [New Post] Bitcoin is becoming much more important in Hong Kong and India.
5    Reports are surfacing that some Hong Kong ATMs have run out of cash as
6    Bitcoin is the most transparent currency ever created.
R로 소셜 미디어 데이터 분석하기

Ayo berlatih!

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

Preparing Video For Download...