Sentiment analysis with TextBlob

TextBlob gives you sentiment analysis, scoring, and classification in a couple of Python lines. For the given a text, initialize a TextBlob instance, and retrieve its polarity with these two lines of code:

from textblob import TextBlobprint(TextBlob(text).sentiment)

The TextBlob sentiment object has a polarity and a subjectivity score. The polarity of a text ranges from -1 to +1, negative to positive, and the subjectivity from 0 to 1, very objective to very subjective. For instance, the sentence I love brocoli returns Sentiment(polarity=0.5, subjectivity=0.6), while the sentence I hate brocoli returns a sentiment of Sentiment(polarity=-0.8, subjectivity=0.9).  We can add the TextBlob sentiment whenever we ...

Get Effective Amazon Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.