Sentiment Analysis using TextBlob
TextBlob is a Python (2 and 3) library for processing textual data. It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more.
Installation
pip install textblob
Features
- Noun phrase extraction
- Part-of-speech tagging
- Sentiment analysis
- Classification (Naive Bayes, Decision Tree)
- Language translation and detection powered by Google Translate
- Tokenization (splitting text into words and sentences)
- Word and phrase frequencies
- Parsing
- n-grams
- Word inflection (pluralization and singularization) and lemmatization
- Spelling correction
- Add new models or languages through extensions
- WordNet integration
Create a TextBlob
First, the import.
from textblob import TextBlob
Sentiment Analysis
The sentiment property returns a named tuple of the form Sentiment(polarity, subjectivity)
.
>>> testimonial = TextBlob("Textblob is amazingly simple to use. What great fun!")
>>> testimonial.sentiment
Sentiment(polarity=0.39166666666666666, subjectivity=0.4357142857142857)
The polarity score is a float within the range [-1.0, 1.0] where 1 means positive statement and -1 means a negative statement.
>>> testimonial.sentiment.polarity
0.39166666666666666
Subjective sentences generally refer to personal opinion, emotion or judgment whereas objective refers to factual information.. The subjectivity is a float within the range [0.0, 1.0] where 0.0 is very objective and 1.0 is very subjective.
>>> testimonial.sentiment.subjectivity
0.4357142857142857
Thanks for reading!!