Live Twitter Sentiment
Analysis
-Shivam Singh
Training and Testing a Classifier
The classifier is Naïve
Bayes in nltk library
Save classifier with pickle
Next time we won’t have to
train the classifier again.
We can load the trained
classifier from a file.
Using scikitlearn Classifiers with nltk
Combining Classification Algorithms with vote
The sentiment with
maximum votes is
classified with the
Voted Classifier
Creating and testing the voted classifier
The voted
classifier has a
69% accuracy
in our test
data.
Sentiment Analysis Module
Pickle all classifiers
This saves us
from training
them every
time we run
the program
Analyzing Sentiments of texts
Confidence is the
percentage of
classifiers that
classified the text with
the majority
sentiment.
Getting tweet streams from twitter
High
confidence
tweets are
written in the
file “twitter-
out.txt”
Analyzing tweets for a keyword
We are
printing the
tweet with
the
sentiment
classified and
the
confidence
of the
classification.
Plotting the
sentiment graph
using matplotlib
For every positive
sentiment:
the graph moves up by 1
unit
For every negative
sentiment:
the graph moves down by
1 unit
Result: LIVE Sentiment Graph for tweets of a
particular keyword
The keyword
used is “happy”
thus has a lot
of positive
sentiment

Twitter Sentiment Analysis with Python