트위터 감성 분석

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

Vivek Vijayaraghavan

Data Science Coach

학습 개요

  • 감성 분석이란?
  • 트윗에 감성 분석 적용
  • 사람들의 감정과 의견 해석
R로 소셜 미디어 데이터 분석하기

감성 분석

  • 제품/브랜드에 대한 인식 파악
  • 긍정·부정·중립 의견 추출 및 정량화
  • 신뢰, 기쁨, 분노 등 감정 추출

감성 분석 감정

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

감성 분석의 중요성

  • 고객 인식은 구매 결정에 영향
  • 고객의 현재 감정을 파악하는 데 도움
  • 고객 의견을 선제적으로 청취하고 직접 소통
R로 소셜 미디어 데이터 분석하기

감성 분석 작동 원리

  • 미리 정의된 감성 사전으로 점수 계산
  • 단어의 의미/의도에 따라 학습·채점
  • 각 단어는 긍정/부정과의 유사도로 점수 부여
  • 특정 감정을 표현하는 단어로 확장
R로 소셜 미디어 데이터 분석하기

감성 분석 단계

감성 분석 단계 1

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

감성 분석 단계

감성 분석 단계 2

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

감성 분석 단계

감성 분석 단계 3

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

감성 분석 단계

감성 분석 단계 4

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

감성 분석용 트윗 추출

# Extract tweets on galaxy fold
twts_galxy  <-  search_tweets("galaxy fold", n = 5000, 
                                lang = "en", include_rts = FALSE)
R로 소셜 미디어 데이터 분석하기

감성 분석 수행

# Perform sentiment analysis for tweets on galaxy fold
library(syuzhet)
sa.value <- get_nrc_sentiment(twts_galxy$text)
R로 소셜 미디어 데이터 분석하기

감성 점수 확인

# View the sentiment scores
sa.value[1:5,1:7]
anger    anticipation    disgust    fear    joy    sadness    surprise
<dbl>       <dbl>         <dbl>     <dbl>  <dbl>    <dbl>       <dbl> 
0             0             0         0      0        0           0
1             0             0         0      0        0           0
1             1             0         2      1        1           1
0             0             0         1      0        0           0
0             0             0         0      0        0           0
R로 소셜 미디어 데이터 분석하기

감성 점수 합계

# Calculate sum of sentiment scores
score <- colSums(sa.value[,])
R로 소셜 미디어 데이터 분석하기

감성 점수 데이터 프레임

# Convert to data frame
score_df <- data.frame(score)
# View the data frame
score_df
               score
               <dbl>
anger           211            
anticipation    825            
disgust         214            
fear            253            
joy             412            
sadness         197            
surprise        315            
trust           641            
negative        487            
positive       1351
R로 소셜 미디어 데이터 분석하기

감성 점수 데이터 프레임

# Convert row names into 'sentiment' column
# Combine with sentiment scores
sa.score <- cbind(sentiment = row.names(score_df), 
                  score_df, row.names=NULL)
R로 소셜 미디어 데이터 분석하기

감성 점수 데이터 프레임

# View data frame with sentiment scores
print(sa.score)
sentiment      score
<fct>         <dbl>
anger           211            
anticipation    825            
disgust         214            
fear            253            
joy             412            
sadness         197            
surprise        315            
trust           641            
negative        487            
positive        1351    
R로 소셜 미디어 데이터 분석하기

감정 시각화

  • ggplot()으로 감정 시각화
# Plot the sentiment scores
ggplot(data = sa.score2, aes(x = sentiment, y = score, 
       fill = sentiment)) +
       geom_bar(stat = "identity") +
       theme(axis.text.x = element_text(angle = 45, hjust = 1))
R로 소셜 미디어 데이터 분석하기

감정 시각화

감정 시각화

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

연습해 봅시다!

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

Preparing Video For Download...