การวิเคราะห์ความรู้สึก

การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

Alex Hanna

Computational Social Scientist

ทำความเข้าใจการวิเคราะห์ความรู้สึก

  • วิธีการ
    • นับคำเชิงบวก/เชิงลบในเอกสาร
    • ประเมินความเป็นบวก/ลบของเอกสารทั้งหมด
  • การใช้งาน
    • วิเคราะห์ปฏิกิริยาต่อบริษัท ผลิตภัณฑ์ นักการเมือง หรือนโยบาย
การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

เครื่องมือวิเคราะห์ความรู้สึก

  • VADER SentimentIntensityAnalyzer()
    • เป็นส่วนหนึ่งของ Natural Language Toolkit (nltk)
    • เหมาะกับข้อความสั้น เช่น ทวีต
    • วัดความรู้สึกของคำเฉพาะ (เช่น angry, happy)
    • คำนึงถึงความรู้สึกของอีโมจิ (😀) และการพิมพ์ตัวพิมพ์ใหญ่ (Nice vs NICE) ด้วย
การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

การนำการวิเคราะห์ความรู้สึกไปใช้

from nltk.sentiment.vader import SentimentIntensityAnalyzer

sid = SentimentIntensityAnalyzer()
sentiment_scores = tweets['text'].apply(sid.polarity_scores)
การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

การตีความคะแนนความรู้สึก

  • อ่านทวีตเป็นส่วนหนึ่งของกระบวนการ
    • มี face validity หรือไม่? (กล่าวคือ ผลลัพธ์สอดคล้องกับความเข้าใจเรื่องความเป็นบวกหรือลบหรือเปล่า?)
การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

การตีความคะแนนความรู้สึก

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}
การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

การคำนวณค่าเฉลี่ยความรู้สึก

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()
การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

การพล็อตคะแนนความรู้สึก

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()

ความรู้สึกของ Facebook เทียบกับ Google

การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

มาฝึกกันเถอะ!

การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

Preparing Video For Download...