Phân tích cảm xúc

Phân tích dữ liệu mạng xã hội bằng Python

Alex Hanna

Computational Social Scientist

Tìm hiểu phân tích cảm xúc

  • Phương pháp
    • Đếm số từ tích cực/tiêu cực trong văn bản
    • Đánh giá mức tích cực/tiêu cực của toàn văn bản
  • Ứng dụng
    • Phân tích phản ứng với công ty, sản phẩm, chính trị gia hoặc chính sách
Phân tích dữ liệu mạng xã hội bằng Python

Công cụ phân tích cảm xúc

  • VADER SentimentIntensityAnalyzer()
    • Một phần của Natural Language Toolkit (nltk)
    • Hiệu quả cho văn bản ngắn như tweet
    • Đo cảm xúc của từng từ (ví dụ: angry, happy)
    • Cũng xét đến cảm xúc của emoji (😀) và viết hoa (Nice vs NICE)
Phân tích dữ liệu mạng xã hội bằng Python

Triển khai phân tích cảm xúc

from nltk.sentiment.vader import SentimentIntensityAnalyzer

sid = SentimentIntensityAnalyzer()
sentiment_scores = tweets['text'].apply(sid.polarity_scores)
Phân tích dữ liệu mạng xã hội bằng Python

Diễn giải điểm cảm xúc

  • Đọc tweet trong quá trình xử lý
    • Có "độ tin cậy bề mặt" không? (tức là có khớp với hiểu biết của tôi về tích cực hay tiêu cực không?)
Phân tích dữ liệu mạng xã hội bằng Python

Diễn giải điểm cảm xúc

tweet1 = 'RT @jeffrey_heer: Thanks for inviting me, and thanks 
for the lovely visualization of the talk! ...'
print(sid.polarity_scores(tweet1))
{'neg': 0.0, 'neu': 0.496, 'pos': 0.504, 'compound': 0.9041}
tweet2 = 'i am having problems with google play music'
print(sid.polarity_scores(tweet2)
{'neg': 0.267, 'neu': 0.495, 'pos': 0.238, 'compound': -0.0772}
Phân tích dữ liệu mạng xã hội bằng Python

Tạo điểm cảm xúc trung bình

sentiment = sentiment_scores.apply(lambda x: x['compound'])

sentiment_fb = sentiment[check_word_in_tweet('facebook', tweets)] .resample('1 min').mean() sentiment_gg = sentiment[check_word_in_tweet('google', tweets)] .resample('1 min').mean()
Phân tích dữ liệu mạng xã hội bằng Python

Vẽ biểu đồ điểm cảm xúc

plt.plot(
    sentiment_fb.index.minute, 
    sentiment_fb, color = 'blue'
    )
plt.plot(
    sentiment_g.index.minute, 
    sentiment_gg, color = 'green'
    )   
plt.xlabel('Minute')
plt.ylabel('Sentiment')
plt.title('Sentiment of companies')
plt.legend(('Facebook', 'Google'))
plt.show()

Cảm xúc: Facebook vs. Google

Phân tích dữ liệu mạng xã hội bằng Python

Cùng luyện tập nào!

Phân tích dữ liệu mạng xã hội bằng Python

Preparing Video For Download...