Sentiment Analysis
Tags: machinelearning, classification
Published: 2017-08-13 05:42:15

---
title: Sentiment Analysis
published: true
description: A brief on sentiment analysis and the accuracy of predictions.  
tags: MachineLearning, ML, Classification 
canonical_url: http://techscouter.blogspot.in/2017/07/sentiment-analysis.html
cover_image: https://thepracticaldev.s3.amazonaws.com/i/4ffgiklzmwai437g68qw.png
---

<div dir="ltr" style="text-align: left;" trbidi="on">


<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-4p-ndHTS-gg/WWJ4aq9VRlI/AAAAAAAABmg/Y5fnLzIReqkw6N78qTKyoFBH9b0jpsvHACLcBGAs/s1600/sentiment.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="240" data-original-width="320" src="https://3.bp.blogspot.com/-4p-ndHTS-gg/WWJ4aq9VRlI/AAAAAAAABmg/Y5fnLzIReqkw6N78qTKyoFBH9b0jpsvHACLcBGAs/s1600/sentiment.jpg" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>

This one took long due to the Analysis work I was doing for this post.There is a lot of work going on in the subject of Sentiment analysis so I decided to compare the accuracy of the products. Let's start with some basics...

<h2 style="text-align: left;">
NLP: Natural Language Processing</h2>
<div>
Natural Language Processing is a very interesting topic and a subject of debate when it comes to accuracy of the NLP.</div>
<div>
Natural Language is very ambiguous as same sentences can have different meanings like</div>
<i><span style="font-size: large;">
</span></i> <i><span style="font-size: large;">"I saw a man on a hill with a telescope. "</span></i>
<div>

</div>
<div>
It seems like a simple statement until you begin to unpack the many alternate meanings:
<ul style="text-align: left;">
<li>There’s a man on a hill, and I’m watching him with my telescope.</li>
<li>There’s a man on a hill, who I’m seeing, and he has a telescope.</li>
<li>There’s a man, and he’s on a hill that also has a telescope on it.</li>
<li>I’m on a hill, and I saw a man using a telescope.</li>
<li>There’s a man on a hill, and I’m seeing him with a telescope.</li>
</ul>
Sarcasm is that component of the language that is difficult for quite a few humans to understand.
<h3 class="subbuzz__title  xs-mb1 bold" style="box-sizing: inherit; line-height: 1.2; margin: 0px 0px 1rem; padding: 0px; text-align: left;">
<span style="font-size: small; font-weight: normal;">Phrase:</span><span style="font-size: small; font-weight: normal;"> <i>"Great job."</i></span></h3>
<h3 class="subbuzz__title  xs-mb1 bold" style="box-sizing: inherit; line-height: 1.2; margin: 0px 0px 1rem; padding: 0px; text-align: left;">
<span style="font-size: small; font-weight: normal;">Normally means:</span><span style="font-size: small; font-weight: normal;"><span style="font-weight: normal;"> You have created something of value here.</span>
Sarcastic way means:</span><span style="font-size: small; font-weight: normal;"> You have created nothing of value here.</span>
<span style="font-size: small; font-weight: normal;">
</span> <span style="font-size: small; font-weight: normal;">Also every day there are some new slangs added in the vocabulary like ROFL, LOL, NaMo, BrExit etc...</span></h3>
<div>
<span style="font-size: small; font-weight: normal;">The presence of all these components in the language makes it much more difficult to process it.</span></div>
<div>
<span style="font-size: small; font-weight: normal;">
</span></div>
<h2 style="text-align: left;">
Sentiment Analysis</h2>
<div>
It is a sub-domain of NLP which is basically a binary classification problem[To know more about ML and classification check my post<b>&nbsp;[<a href="http://techscouter.blogspot.in/2017/06/machine-learning-solution-or-problem.html" target="_blank">Machine Learning -A Solution or Problem</a></b>]</div>
<div>
The problem is to determine the polarity i.e the negativity or positivity of a sentence by processing the sentence and applying some algorithm to it.</div>
<div>
One of the naive approach for calculating the polarity of the sentence is Bag of Words Technique.</div>
<div>
In this technique, a sentence is simply broken into words and these words are then mapped to a dictionary which contains words and the polarity of the corresponding word.The total polarity of a sentence is calculated by summing up the individual&nbsp;words. An example of such dictionary is <a href="http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010" target="_blank">AFINN</a>.</div>
<div>
<span style="font-size: small; font-weight: normal;">
</span></div>
<div>
<span style="font-size: small; font-weight: normal;">But this is pretty basic approach and works only for very simple sentences and not effective for complex language. There are many other algorithms like SVM, Maximum Entropy etc which calculate the polarity by form a relationship between the words.</span></div>
<div>

</div>
<h2 style="text-align: left;">
Twitter Sentiment Analysis</h2>
<div>
Twitter is a very popular social network where information spreads like a fire and reaches millions of users within seconds. Twitter sentiment analysis is a subject in which the Twitter&nbsp;tweets are analysed for calculating polarities and then a social notion about a topic is estimated.</div>
<div>
There are many products in the market that claim to provide market analysis based on the Twitter data.
A big question on this type of &nbsp;analysis is that if it is difficult to understand the natural language and even after too much research its accuracy in sentiment analysis is at most 85%, how difficult it is to classify a twitter&nbsp;tweet into positive or negative tweet by just 160 characters, also these tweets have lots of jargons and slangs.

To explore this I took a set of 100 tweets and ran sentiment analysis through three models

<ol style="text-align: left;">
<li>IBM Watson</li>
<li>CoreNLP by Stanford</li>
<li>Microsoft Cognitive Service</li>
<li>Manual Tagging</li>
</ol>
There was a maximum accuracy of 50% and all the models nearly performed equally well.
The results can be seen <a href="https://docs.google.com/spreadsheets/d/1c-QD_t3vpPWG-BNTr2xBXZUfZDaHi873MKbaQASnusQ/edit?usp=sharing" target="_blank">here</a>.
One thing that was clear from this analysis is that

<i><span style="font-size: large;">"Either we can not depend on Twitter's tweet data for Market Analysis and Predictions through Sentiment Analysis or we need a more sophisticated system to do the analysis."</span></i></div>
</div>
</div>