Database Reference
In-Depth Information
Projecting data using PCA on the LFW dataset
We will illustrate this concept by projecting each LFW image into a ten-dimensional vec-
tor. This is done through a matrix multiplication of the image matrix with the matrix of
principal components. As the image matrix is a distributed MLlib RowMatrix , Spark
takes care of distributing this computation for us through the multiply function:
val projected = matrix.multiply(pc)
println(projected.numRows, projected.numCols)
This will give you the following output:
(1055,10)
Observe that each image that was of dimension 2500 has been transformed into a vector of
size 10. Let's take a look at the first few vectors:
println(projected.rows.take(5).mkString("\n"))
Here is the output:
[2648.9455749636277,1340.3713412351376,443.67380716760965,-353.0021423043161,52.53102289832631,423.39861446944354,413.8429065865399,-484.18122999722294,87.98862070273545,-104.62720604921965]
[172.67735747311974,663.9154866829355,261.0575622447282,-711.4857925259682,462.7663154755333,167.3082231097332,-71.44832640530836,624.4911488194524,892.3209964031695,-528.0056327351435]
[-1063.4562028554978,388.3510869550539,1508.2535609357597,361.2485590837186,282.08588829583596,-554.3804376922453,604.6680021092125,-224.16600191143075,-228.0771984153961,-110.21539201855907]
[-4690.549692385103,241.83448841252638,-153.58903325799685,-28.26215061165965,521.8908276360171,-442.0430200747375,-490.1602309367725,-456.78026845649435,-78.79837478503592,70.62925170688868]
[-2766.7960144161225,612.8408888724891,-405.76374113178616,-468.56458995613974,863.1136863614743,-925.0935452709143,69.24586949009642,-777.3348492244131,504.54033662376435,257.0263568009851]
As the projected data is in the form of vectors, we can use the projection as input to another
machine learning model. For example, we could use these projected inputs together with a
set of input data generated from various images without faces to train a facial recognition
model. Alternatively, we could train a multiclass classifier where each person is a class,
thus creating a model that learns to identify the particular person that a face belongs to.
Search WWH ::




Custom Search