Simple facial analysis and visualization with R

Shuye Han
Posted on Jul 25, 2016

In this project, I took a general tour to explore the facial features and conducted several simple analysis based on R. The facial features analysis, which is quite a hot topic in machine learning and neural network, is really a large domain and requires various techniques and tools for assistance. R, along with its large amount of packages and visualization tools like "ggplot", is one of the most useful programming languages in applying facial detection and recognition approaches.

Though real detection and recognition tasks involve complicated processes like multiple layer deep learning or artificial neural network, this project would not go that deep into the real application level. Rather, this small project would just take me into a comprehensive view of how R functions work on analyzing the facial features and give some simple but meaningful visualization views.

We begin our tour by listing all the packages that would be needed afterwards. Some of them are used for data transformation and some of them are used for visualization.

屏幕快照 2016-07-24 下午9.19.14

Then the training and testing sets are read from csv files into R. Note that a single entity set in training set includes 30 numeric features and an image matrix depicting the pixel values of its image. Since the image matrix is large compared with other features, they are often retrieved from the raw dataset and stored separately in another dataframe.

屏幕快照 2016-07-24 下午9.21.08`

And since the data frame is pretty large, we would like to store it as a temporal file as 'data.Rd' in case that we might accidentally lose it in the environment.

屏幕快照 2016-07-24 下午9.28.38

After all the transformations are done, we can concentrate on some simple analysis for the whole image dataset. We can first plot all the key points onto one graph to see the overall distribution of how those key points are located. We can also assign different colors to different key points.

屏幕快照 2016-07-24 下午9.30.04

屏幕快照 2016-07-24 下午9.40.50



After aggregation, we can see the average key points of all the faces.

屏幕快照 2016-07-24 下午9.41.48


We can see some pictures with extreme points largely deviated from the center.


屏幕快照 2016-07-24 下午9.42.02



Instead of looking at a single feature, we could analyze the correlation between multiple features. Like Euclidean distance between left eye centers and right eye centers.

屏幕快照 2016-07-24 下午9.44.09Rplot07Rplot08Rplot09

Lets make a simple try by assigning all the keypoints of test images the same location, the mean value of all the keypoints in training images. When submitting this online, you will get a very low score 3.96244.

屏幕快照 2016-07-24 下午9.44.22

Since the website doesn't give us the answer for the test set, we can build a complete test set by our own through splitting the original training set into two sub sets training and testing. We will split the whole training set through four different ways: 5 equivalent subsets, 10 equivalent subsets, 15 equivalent subsets, 20 equivalent subsets. In each way, one out of the whole subsets would be used as the test set while the others to be the training sets.

屏幕快照 2016-07-24 下午9.44.50


Now lets try different splitting methods.

屏幕快照 2016-07-24 下午9.45.10

It seems different splitting methods don't influence much on the result. Now let's use a comparatively more complicated method called patching.

屏幕快照 2016-07-24 下午9.45.01


Now lets test our models one by one.


屏幕快照 2016-07-24 下午9.45.30



About Author

Leave a Comment

yalei November 9, 2016
Do you have a conclusion after testing model one by one?

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp