Web Scraping and Facial Expression Analysis
12
|
Predicting Facial Expression from Data
Introduction
Similarly to the last chapter, this chapter will process each piece of data separately so we can aggregate results. This will provide trends for any specific CEO in terms of predicted facial expression.

Facial Expression for Each Image

The function Classify in Wolfram Language is a very powerful function to access built-in machine learning models. When used with the first argument of FacialExpression, Classify predicts the facial expression of that image. As in the previous chapter, Table can be used to run that command on each of the images, returning a new list of values corresponding to the facial expression prediction for that image. We can also use ImageCollage to more easily visually inspect the original set of images for undesired results:
In[]:=
faceExpression=Table[Classify["FacialExpression",image],{image,allFaces}]
Out[]=

happiness
,
happiness
,
happiness
,
happiness
,
sadness
,
happiness
,
happiness
,
happiness
,
happiness
,
neutral
,
happiness
,
happiness
,
happiness
,
happiness
,
happiness
,
sadness
,
happiness
,
happiness

Tally is a very useful function to count how many times a particular value is present in a dataset. In this case, 15 of the images have a predicted facial expression of happiness, which is an overwhelming majority:
In[]:=
Tally[faceExpression]
Out[]=

happiness
,15,
sadness
,2,
neutral
,1
To display final results, we can build a collage of all the images and use TextGrid to display the frequency of predicted facial expressions:
In[]:=
ImageCollage[allFaces]​​TextGrid[Tally[faceExpression],Frame->All]
Out[]=
Out[]=
happiness
15
sadness
2
neutral
1

Summary

This analysis might have seemed to take significant effort to create. But now that it is finished, you can change the initial definitions for ceo and company and rerun this analysis multiple times for multiple CEOs. This provides a very convenient way to compare CEOs (or any public figure) against one another.
DownloadNotebook»