Twitter Battle For The Gujarat Elections

Now that both the phases of election in Gujarat are over, it’s time to predict whose going to win the Gujarat battle-2017. Almost all the exit polls have predicted that the BJP will retain Gujarat and is expected to get more than 110 seats.

Of the seven polls that were available on Gujarat, three organisations indicated that BJP was likely to get fewer seats than in 2012, when it had won 115. Two of the polls predicted a result very similar to five years ago while the two others indicated that the saffron party would beat its 2002 record of 127 seats in the state.

Below are the exit poll results of various leading Media Organisations in India:

We at Nikhil Analytics also tried to predict the results of Gujarat Elections using Text Analysis in R by extracting data from Twitter and used Sentiment Analysis to draw insights from the sentiments of people tweeting on The Gujarat Elections. The results obtained show the BJP is ahead of Congress by a comfortable margin. To do this, we used R programming to fetch tweets from twitter by authenticating and connecting a twitter account and considering the most trending #tags on the Gujarat Elections. At first we created a word cloud to see the most frequently occurring words using #GujaratElection. We found #NarendraModi, @BJP4India, #RahulGandhi and @INCIndia were the most frequently occurring words. So, we used these as a reference to extract tweets containing these words using searchTwitter function We categorised the first two reference(#NarendraModi and @BJP4India) as data for BJP and the remaining (#RahulGandhi and @INCIndia) as data for Congress. Then we got the text of all the extracted tweets. We then joined the texts for BJP and Congress and removed the duplicate tweets out of it. We created a function to clean the text like removing punctuations, digits, http links and emoticons. We then used clean.text function to clean the data completely and joined the cleaned text into a single vector. We created a corpus using Corpus function. We removed stopwords in English and a number of other words that were not meant to be a part of the result. We created a term document matrix and formed a word cloud to get an idea about the content of tweets. Then we added column names to the term document matrix (“BJP,”Congress”). Finally we carried out sentiment Analysis for both BJP and Congress by fetching emotion categories best fit for our analysis purpose. We used emotion as one category and polarity of sentiments as another category and built a histogram using ggplot library for both BJP and Congress to learn about the emotions and sentiments people carry and what they feel about a certain party.

Word cloud comparing the frequencies of words between BJP and Congress.

Sentiment analysis of tweets for Congress.

Sentiment analysis of tweets for BJP.

Sentiment analysis of tweets by Emotional Categories.

Final Sentiment Analysis of Tweets – BJP has greater positive sentiments than Congress.

Word Cloud for Exit Poll predictions.


We can clearly see that people have mixed feelings about both parties competing for power in the state. But it’s the BJP who is leading the race at the moment. Let’s wait and watch who is going to win this important election on the 18th of Dec, 2017.








About Avijeet Biswal :

Avijeet Biswal is B.Tech in Computer Science. Currently he is working as Analyst Intern with NikhilGuru Consulting Analytics Service LLP (Nikhil Analytics), Bangalore.


4 Comments on "Twitter Battle For The Gujarat Elections"

  1. Hari Chandan Patnaik | December 18, 2017 at 9:56 pm | Reply

    As it was a close neck to neck fight between BJP nd INC definitely it was very difficult to predict early who will lead. Congrats Avijeet biswal n Nikhil Analytics for ur fantastic prediction which goes correct.

  2. This is power of analytics,how emotions of human being is calculated using R with help of sentiment analysis,In article we can see various emotions which help us decide who’s gonna win. Nikhil analytics prediction

Leave a comment

Your email address will not be published.



Subscribe for Data Analytics Edge Newsletter & Share..:-)

error: Content is protected !!