Comparing VADER and Text Blob to Human Sentiment | by Leah Pope | Dec, 2020

[ad_1]


Photo by Tim Mossholder on Unsplash
import pandas as pd
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
tweets = pd.read_csv('../data/prepped_sxsw_tweets.csv')# Get the VADER sentiments
def get_vader_sentiment(analyzer, tweet):
tweet = tweet.replace('#','') # include hashtag text
vader_scores = analyzer.polarity_scores(tweet)
compound_score = vader_scores['compound']
vader_sentiment = None
# using thresholds from VADER developers/researchers
if (compound_score >= 0.05):
vader_sentiment = 'positive'
elif (compound_score < 0.05 and compound_score > -0.05):
vader_sentiment = 'neutral'
elif (compound_score <= -0.05):
vader_sentiment = 'negative'
return vader_sentimentanalyzer = SentimentIntensityAnalyzer()
tweets['vader_sentiment'] = tweets.apply(lambda row: get_vader_sentiment(analyzer, row['tweet_text']), axis=1)tweets.head(3)
(author’s own image)
  • neutral: (compound score > -0.05) and (compound score < 0.05)
  • negative: compound score <= -0.05
Photo by Damir Mijailovic on Pexels
from textblob import TextBlobdef get_text_blob_sentiment(tweet):
polarity = TextBlob(tweet).sentiment.polarity
# The polarity score is a float within the range [-1.0, 1.0].
textblob_sentiment = None
if (polarity > 0):
textblob_sentiment = 'positive'
elif (polarity == 0):
textblob_sentiment = 'neutral'
elif (polarity < 0):
textblob_sentiment = 'negative'
return textblob_sentiment
tweets['text_blob_sentiment'] = tweets.apply(lambda row: get_text_blob_sentiment(row['tweet_text']), axis=1)tweets.head(3)
(author’s own image)
Photo by Marten Newhall on Unsplash
(author’s own image)
  • 41.70% VADER Neutral, 37.00% Text Blob Neutral
  • 45.40% VADER Positive, 49.30% Text Blob Positive
# Get the VADER sentiments
analyzer = SentimentIntensityAnalyzer()
apple_tweets['vader_sentiment'] = apple_tweets.apply(lambda row: get_vader_sentiment(analyzer, row['text']), axis=1)
# Get the Text Blob sentiments
apple_tweets['text_blob_sentiment'] = apple_tweets.apply(lambda row: get_text_blob_sentiment(row['text']), axis=1)
apple_tweets.head(3)
(author’s own image)
(author’s own image)
  • 34.90% VADER Neutral, 42.80% Text Blob Neutral
  • 32.10% VADER Positive, 32.40% Text Blob Positive
---- Apple and Google @ SXSW Tweets -----
28.60% of Neutral Tweets could be re-labeled.
24.50% of Neutral Tweets could be re-labeled to Positive.
4.10% of Neutral Tweets could be re-labeled to Negative.
---- Apple Tweets -----
21.00% of Neutral Tweets could be re-labeled.
18.50% of Neutral Tweets could be re-labeled to Positive.
2.50% of Neutral Tweets could be re-labeled to Negative.

Read More …

[ad_2]


Write a comment