Twitter Election Prediction

Predicting the 2016 presidential nominees using sentiment analysis on tweets about the presidential candidates.

View on GitHub Download .zip Download .tar.gz


Using social media for political analysis is becoming a common practice, especially during election time. Many researchers and media are trying to use social media to understand the public opinion and trend. This project investigated how we could use Twitter to predict public opinion and thus predict American presidential primary election results. I analyzed thousands of tweets from September - December 2015 to predict the outcome of the 2016 primary election.


Twitter, Facebook, and Google+ have become very popular communication tools for Internet and Mobile users. These platforms enable more than friendly chatter and individual expression; they facilitate remarkably diverse and broad participation while accelerating the formation of effective collaborations. Authors of those messages write about their life, share opinions on a variety of topics and discuss current issues. As more and more users post about products and services they use or express their political and religious views, social media websites become valuable sources of people’s opinions and sentiments. Such data can be efficiently used for marketing or social studies. In this study, the Information gather is from Twitter users.

Data Sets

In this experiment, we use two different sets of Data. The first set is a sentiment analysis of English tweets to determine if the Tweet is positive or negative. The second dataset is a partisan analysis of English tweets to determine if the tweet is democratic or republican.

Sentiment Analysis

The sentiment analysis dataset came from the organization Sentiment140 (formerly known as "Twitter Sentiment"). The purpose of Sentiment140 allows you to discover the sentiment of a brand, product, or topic on Twitter.

Partisan Analysis

The partisan analysis dataset came from a collection of tweets from United States Congress Members with Twitter Accounts. To create this dataset, we collected the tweets from the 2015 year and classified the tweet with the politician's party. The list of tweeter accounts came from Tweet Congress lists: Democrat Tweets, Republican Tweets.