Election 2016: Tracking Emotions with R and Python

October 21, 2016
By

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

Temperament has been a key issue in the 2016 presidential election between Hillary Clinton and Donald Trump, and an issue highlighted in the series of three debates that concluded this week. Quantifying “temperament” isn’t an easy task, but The Economist used the Microsoft Emotion API to chart the anger, contempt, sadness and surprised expressed in the faces of the candidates during key sequences of the debates, like this from the third debate:

Economist Data Journalist Ben Heubl explains how you can analyze emotions in a video file using Python and R. The Emotion API provides scores for eight attributes of emotion as expressed by a face in a still image or video clip. For example, this expression by Donald Trump expresses mostly anger, with a touch of disgust and a soupçon of contempt.

Face4

Ben provides Python code for passing a video clip into the Emotion API and retriving frame-by-frame emotion scores. He then uses R to analyze and chart the scores: mostly happiness for Clinton; mostly sadness for Trump.

Facial

Ben points out that emotion and sentiment analysis can be useful tools for data journalists, noting for example:

Facial recognition data, as the one that we collected via the Microsoft emotion API, suggests that when Trump is challenged with arguments which he doesn’t like, his facial attitude changes. In the second debate, Clinton provoked him with mentioning his involvement in degrading a former Miss Universe. His expression promptly changed to a mixture of an angry and sad expression.

For more analysis of emotion in the debates, including a text-based sentiment analysis of the debate transcript, check out Ben’s complete blog post linked before. And be sure to check out the original article about the debates from The Economist.

Ben Heubl: How to apply face recognition API technology to data journalism with R and python

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)