Discovering sentiment analysis
In this recipe, we will use two simple tools for labeling a sentence as having positive or negative sentiment. The first tool is the NLTK Vader sentiment analyzer, and the second one uses the textblob
package.
Getting ready
We will need the nltk
and textblob
packages for this recipe. If you haven't already installed them, install them using these commands:
pip install nltk pip install textblob
In addition to this, you will need to run the following from Python the first time you use the Vader sentiment analyzer:
>> import nltk >>nltk.download('vader_lexicon')
How to do it…
We will define two functions: one will do sentiment analysis using NLTK, and the other using TextBlob.
Your steps should be formatted like so:
- Import the packages:
from textblob import TextBlob from nltk.sentiment.vader import SentimentIntensityAnalyzer
- Define the
sentences
list:sentences = ["I love going to school...