Simple facial analysis and visualization with R

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 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans 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 boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis 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 seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI