PCA of Flags

Hi all,

I have created a tutorial on Principal Components analysis based on flags:

https://observablehq.com/@stschiff/pca-of-flags

(in case you’ve seen this a couple of weeks back, I have substantially beefed it up now).

The notebook introduces the key machinery behind PCA, using Eigen-Decomposition of the sample-by-sample (in my case flag-by-flag) covariance matrix. All computation and data-loading happens in the browser, there is no precomputed data. Really nice to see how all of this linear algebra is so doable and performant in the browser. I am also making use of some interactive elements, like tooltips over the covariance matrix, and a flag-picker to compare low-rank approximation to a real flag.

This is great! I wrote one paper on PCA in undergrad 13 years ago and it is nice to have a refresher. Makes me wanna see all global flags. Or I could draw a flag and see it projected onto the space…

I’m also wondering, how does the representation of the flag affect the analysis? If instead of raster pixels, the vector represented an SVG, or pre-computerized instructions for sewing fabric, or a prose description of the flag as originally set down in law. E.g., the flags of Indonesia :indonesia: and Poland :poland: share zero pixels, but have obvious similarities. Does the PCA pick that up? And how would that depend on how you encoded the flags?

Well, these are all very good questions. I started this as a tutorial for students learning about PCA for genetic data, so a handful of flags like this already suffice in this case.

About the representation: I suppose when it comes to SVG, sewing instructions or prose description etc., one would go the path via Multidimensional scaling (MDS). It starts with some distance metric, and performs very similar math to arrive at a low-dimensional representation (under specific conditions, MDS and PCA are equivalent). And when it comes to distances, you can think of other meaningful distance measures than pixel-differences. In SVG space, I guess it could be the vector instructions themselves that could somehow inform a distance, and then it could give meaningful results.

Hadn’t heard of MDS! ty! hm Multidimensional scaling - Wikipedia