how does TextBlob calculate an empirical value for the sentiment polarity. I have used naive bayes but it just predicts whether it is positive or negative. How could I calculate a value for the sentiment like TextBlob does?
Here is an example from the site: https://textblob.readthedocs.io/en/dev/quickstart.html#sentiment-analysis
text1 = TextBlob("Today is a great day, but it is boring")
text1.sentiment.polarity
# You can derive the sentiment based on the polarity.
Here is a sample code of how I used TextBlob in tweets sentiments:
from textblob import TextBlob
### My input text is a column from a dataframe that contains tweets.
def sentiment(x):
sentiment = TextBlob(x)
return sentiment.sentiment.polarity
tweetsdf['sentiment'] = tweetsdf['processed_tweets'].apply(sentiment)
tweetsdf['senti'][tweetsdf['sentiment']>0] = 'positive'
tweetsdf['senti'][tweetsdf['sentiment']<0] = 'negative'
tweetsdf['senti'][tweetsdf['sentiment']==0] = 'neutral'
Based on the polarity and how the sentences were really sounding, I ended up with the logic above. Note that this might not be the case for some tweets.
I personally found vader sentiments compound score to be making more sense so that I can figure out a range for positive, negative and neutral sentiments based on the compound score & the tweet text instead of just assigning postivie sentiment for all texts with polarity >0