O'Reilly logo

Effective Amazon Machine Learning by Alexis Perrier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required