NLP - Sentiment Analysis Advanced
You want to analyze a batch of short tweets using VADER and classify each as positive if the compound score is above 0.05, negative if below -0.05, and neutral otherwise. Which code snippet correctly implements this?
Afrom vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
tweets = ['Good job!', 'I hate this', 'It is okay.']
results = []
for tweet in tweets:
score = analyzer.polarity_scores(tweet)['compound']
if score > 0.05:
results.append('positive')
elif score < -0.05:
results.append('negative')
else:
results.append('neutral')
print(results)
Bfrom vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
tweets = ['Good job!', 'I hate this', 'It is okay.']
results = []
for tweet in tweets:
score = analyzer.polarity_scores(tweet)['compound']
if score >= 0.05:
results.append('positive')
elif score <= -0.05:
results.append('negative')
else:
results.append('neutral')
print(results)
Cfrom vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
tweets = ['Good job!', 'I hate this', 'It is okay.']
results = []
for tweet in tweets:
score = analyzer.polarity_scores(tweet)['compound']
if score > 0:
results.append('positive')
elif score < 0:
results.append('negative')
else:
results.append('neutral')
print(results)
Dfrom vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
tweets = ['Good job!', 'I hate this', 'It is okay.']
results = []
for tweet in tweets:
score = analyzer.polarity_scores(tweet)['compound']
if score > 0.1:
results.append('positive')
elif score < -0.1:
results.append('negative')
else:
results.append('neutral')
print(results)
