Real-Time Sentiment Analysis of 2020 U.S. Presidential Election

How does divisive language influence politics and the electoral process?

Luke Genung
4 min readJun 11, 2020
Photo by Element5 Digital on Unsplash

Politics are often a contentious topic whether debated on the news or at the dinner table. Any discussion can become emotionally charged and turn into “us vs. them.” As political leaders and their constituents have increasingly used social media, this has created a huge amount of data to analyze the impact of language and emotion on political discourse.

So, how does emotional language shape U.S. politics?

This sentiment analysis model scores novel Twitter content tagged with the three popular hashtags related to the 2020 US presidential election: #2020election, #election2020 and #presidentialelection

The model is 65% accurate in predicting positive vs. negative sentiment about the election. Guessing randomly would yield 33% accuracy, since it is also necessary to filter out neutral content (thus, a 22% improvement).

Lastly, this stack allows running the model and analysis at near real-time for no cost ($0) —

  • Google Sheets as a database: Google Sheets queries the Twitter API every hour and stores all data.
  • Heroku to run the NLTK model: Heroku gets sentiment scores twice a day and pushes data back to Google Sheets (Heroku can do this for free).
  • Tableau Public: Connect Tableau Public to Google Sheets with a Live connection for data analysis.

Analysis

Looking at each category, we can observe the following:

  1. Twitter content about the presidential election is polarized (unsurprisingly).
  2. Twitter sentiment related to the 2020 election skews more negative than positive (unsurprisingly).
  3. There is a large amount of neutral content, where the model could not detect a strong sentiment in one direction or the other.

Now let’s take a deep-dive looking at how this trends over time.

Looking at the timing of peak negativity, content from these 3 election hashtags seems likely to include general political discussions and trending issues as well.

We can see that negative sentiment (in red) shows clear peaks within the following time frames —

March 23–27: Weeks following the start of the COVID-19 pandemic —

  • US reached 20K confirmed cases and 326 deaths.
  • Federal stimulus bill was passed which provided up to $1200 for qualifying adults, $600 of federal unemployment benefits (on top of state unemployment benefits).
  • The stimulus package also provides $500 billion for businesses and municipalities.

Looking at the sentiment distribution geographically, states do not respond with any real consistency. Perhaps this indicates just how chaotic these events were, as states had a wide range of reactions and pandemic regulations —

May 23: Economy begins to re-open with restriction during COVID-19 pandemic

  • COVID-19 pandemic passes 1.5M confirmed cases and 90K deaths in the US
  • Many businesses re-open with restrictions including social distancing and sanitation regulations

May 29-June 2: Death of George Floyd in Minneapolis sparks global protests

  • Peaceful protests are held around many major US cities
  • In response, many cases of police brutality and looting become publicized

Again, looking at this time frame geographically, the country seems to have clear divisions in sentiment about these events.

  • The region around Minnesota, Wisconsin and Iowa can be seen reacting to these events with the most negative sentiment (dark red). Directly relevant to where the protests started.
  • A few historically conservative states (Kentucky, South Carolina) can be seen reacting with positive sentiment (dark green).
  • A few additional states can be seen reacting with positive sentiment (Nevada, Colorado) likely due to these states reopening as their economies were heavily impacted by COVID-19.

Now what?

So, what does all of this tell us? Key questions:

  1. How does language and emotion influence politics?
  2. What can we learn about these events as it relates to the presidential election?
  3. What additional kinds of analysis could help?

Have a look at the Tableau dashboard and let me know what you think!

--

--