程序代写代做代考 algorithm database DATA7703 – Machine Learning for Data Scientists S2 – 2020

DATA7703 – Machine Learning for Data Scientists S2 – 2020
Assignment 2
Eigenfaces & Nearest-Neighbour Classification Due date: Tuesday Sep 8 11:59pm
The goal of the assignment is to implement a nearest-neighbour face recognition algorithm based on Eigenfaces as discussed in Lecture 4 – PCA & LDA. We will be using a database consisting of 10 images each of 40 different people. The image resolution is 32×32, corresponding to the extrinsic dimension of 1024. The task is to correctly identify the person
from a test image using a low-dimensional eigenface representation.
The datasets can be downloaded from the course piazza page, faces_train.txt and faces_train.txt. Each row in these files contain 32×32 = 1024 pixel values. We will be using 7 images per person for training and 3 images for testing. The first 7 images in the training data and the first 3 images in the test data is of person A and so on. The labels for the two datasets are given in faces_train_labels.txt and faces_test_labels.txt.
(In case you are interested, the full ORL face dataset can be found in ORL_faces.zip. Not to be used in this assignment though)
Tasks
1. Load the face database and make sure you understand the file structure. Try and
display some of the images. (You do not have to report on this one)
2. Find the mean face image. Perform PCA on the training faces and extract the top K
components.
3. Compute its K-dimensional projection of the test images onto the face space. That is
find the coordinates of an image expressed using the eigenfaces-basis.
4. Reconstruct the approximated faces and display them as images again. Try this with
different values of K and comment on the results.

5. For each test image, find the training image that is closest (in the sense of Euclidean distance) to the test image in face space, and assign the label (person index) of the training image to the test image. Calculate the recognition rate.
No ML libraries to be used. Numpy, pandas etc. are ok.
Hint: A convenient way to store the data in your implementation is as matrices (numpy arrays). For instance, let Xtrain be a 1024-by-280 matrix, where each column is the image of a single person, and ytrain be a 280×1 vector with all the labels. Numpy supports most, if not all, of the operations needed to implement the above tasks.
What to hand in:
• [40%] The picture of the mean face and top 5 eigenfaces computed by PCA.
• [20%] Pick a face image in the test set, then project and reconstruct this face using different values of K. Show the results for 4 different K’s and comment on the result.
• [30%] A plot of the nearest-neighbour (1NN) classification rate (on the test data) as a function of K. You can choose any sampling of values K from 1 to 1024, as long as it captures the trend of how classification performance changes as a function of K (i.e., we expect performance to be poor for extremely low K, but then to rise very rapidly and level off at some point).
• [10%] Pictures of incorrectly classified faces and their nearest neighbours from the training set for K=100.
Include your code and a brief report addressing the above issues.
When you run your program, it should take a command-line parameter that contains the name of the file containing the training data, training labels, the number of principal components to use (K), the name of the file containing the training data and test labels.
For example (with K=10):
python eigenfacesassignment.py faces_train.txt faces_train_labels.txt 10 faces_test.txt faces_test_labels.txt
Output should be the points above.
For extra credits [20%]:
• Extract a few 32×32 patches from non-face images and investigate their behavior when they are projected onto the “face space”. Project these patches onto the face space for different values of K, and display the reconstructed versions of these
patches, along with the reconstruction errors. Compare the reconstruction errors to those for face images from the database. You can also try it with 32×32 face patches not from the database. Try to decide what threshold on the reconstruction error can distinguish between face and non-face images.
Submission

Assignments to be completed individually and submitted through blackboard.
Due date
Tuesday Sep 8 11:59pm.