Analiza sentimentelor

Analiza datelor din social media în Python

Alex Hanna

Computational Social Scientist

Înțelegerea analizei sentimentelor

  • Metodă
    • Numărarea cuvintelor pozitive/negative din document
    • Evaluarea pozitivității/negativității documentului în ansamblu
  • Utilizări
    • Analiza reacțiilor față de o companie, produs, politician sau politică
Analiza datelor din social media în Python

Instrumente pentru analiza sentimentelor

  • VADER SentimentIntensityAnalyzer()
    • Face parte din Natural Language Toolkit (nltk)
    • Potrivit pentru texte scurte, precum tweet-urile
    • Măsoară sentimentul unor cuvinte specifice (ex. furios, fericit)
    • Ia în considerare și emoji-uri (😀) și majusculele (Nice vs NICE)
Analiza datelor din social media în Python

Implementarea analizei sentimentelor

from nltk.sentiment.vader import SentimentIntensityAnalyzer

sid = SentimentIntensityAnalyzer()
sentiment_scores = tweets['text'].apply(sid.polarity_scores)
Analiza datelor din social media în Python

Interpretarea scorurilor de sentiment

  • Citirea tweet-urilor ca parte a procesului
    • Are validitate aparentă? (adică se potrivește cu ideea de pozitiv sau negativ?)
Analiza datelor din social media în Python

Interpretarea scorurilor de sentiment

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}
Analiza datelor din social media în Python

Calcularea mediilor sentimentelor

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()
Analiza datelor din social media în Python

Reprezentarea grafică a scorurilor de sentiment

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

Sentimentul Facebook vs. Google

Analiza datelor din social media în Python

Să exersăm!

Analiza datelor din social media în Python

Preparing Video For Download...