Sentiment Analysis of Today's Tweets About President Buhari Using Python's Vader and Sentiwordnet

, , 6 comments

After a long weekend crisscrossing Lagos, Kaduna and Abuja to deliver our quarterly Business Data Analysis and In-depth Excel Training in Abuja, I rested today and decided to do an interesting data analysis task. 

Do a sentiment analysis on today's tweets about the President, Buhari.

It was a very interesting task. Made me get familiar with Python's Tweepy library. I got some help from Marco Bonzanini. You should check out his Mastering Social Media Mining with Python book.

Here is the breakdown of the steps in achieving the goal:

  1. Created the needed credentials to access Twitter API (it's at https://apps.twitter.com/app/new)
  2. Use Tweepy to search in realtime for tweets about Buhari
  3. Save the tweets as a JSON file
  4. Handle emoticons and strings peculiar to Twitter (like @, # and so on)
  5. Exclude stop words (words with no significant, for sentiment analysis, meaning) like to, be, is etc
  6. Apply Vader to each tweet text and calculate the entire tweet stream sentiment
  7. Apply Sentiwordnet, an alternative to Vader, to do the same stream sentiment analysis
Below are the screenshots of some of the steps.

Twitter developer setup

Twitter developer setup
Vader Sentiment Analysis results

Sentiwordnet sentiment analysis result
And the results?

Well let's just say if the tweets are a mirror of what people genuinely feel about President Buhari, he should be terribly worried. Most people were very emotional in their tweets about him and overwhelmingly negative.


Vader classified the tweet stream as 54.67% negative vs 17.76% positive and 27.57% neutral.


Sentiwordnet gave a more damning result: 92.06% negative vs 7.48% positive and 0.47% neutral.

Both Vader and Sentiwordnet are rule-based supervised classification algorithms. In a context like Nigeria where we have our own Naija words and peculiar word mix, machine learning algorithm, supervised or non-supervised, might be more reliable.

6 comments:

  1. can you share your coding of twitter analysis

    ReplyDelete
    Replies
    1. Hi Madhu,

      Unfortunately, I can't do that. But I have shared almost all of the code, via the screenshots.

      Delete
  2. Thank you very much for sharing this approach to Twitter sentiment analysis. Have you ever tried setting up an Hadoop Linux box, writing Hadoop code to capture streaming data from Twitter prior to analyzing it?

    ReplyDelete
    Replies
    1. Hi Chikelue,

      Nope, I haven't tried Hadoop. Maybe will sometime in the future and share my experience.

      Thanks.

      Delete

You can be sure of a response, a very relevant one too!

Click on Subscribe by Email just down below the comment box so you'll be notified of my response.

Thanks!