Four 2-D points are (1,2), (2,1), (3,4) and (4,3). What are the sample covariance matrix, the first principal component, the fraction of variance it explains, and the coordinate of the first point along it?

Unsupervised learning, Principal component analysis
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can run PCA by hand from raw points, including centring and the n−1 divisor.

Key idea

Centre the data, form C=1n−1Xc⊤Xc, then find its eigenpairs; the projection of a centred point x on the unit eigenvector u is u⊤x.

Steps

  1. The mean is (2.5,2.5). The centred points are (−1.5,−0.5), (−0.5,−1.5), (0.5,1.5) and (1.5,0.5).
  2. ∑x2=2.25+0.25+0.25+2.25=5, and the same for y2. ∑xy=0.75+0.75+0.75+0.75=3.
  3. Divide by n−1=3: C=[5/3115/3].
  4. For a matrix of the form [abba] the eigenvalues are a±b with eigenvectors (1,1)/2 and (1,−1)/2. So λ1=8/3 and λ2=2/3.
  5. The first principal component is u1=(1,1)/2. It explains 8/310/3=0.8, i.e. 80% of the variance.
  6. The first point's coordinate is u1⊤(−1.5,−0.5)=−2/2=−2≈−1.414.

Common mistakes

How long your answer should be

Half a page; 4–5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: The covariance matrix of a 4-dimensional dataset has eigenvalues 5, 3, 1.5 and 0.5. (a) What fraction of the variance does each principal component explain? (b) How many components are needed to keep at least 90% of the variance? (c) What is the average squared reconstruction error per point when you keep that many?
Next in Unsupervised learning: In matrix factorisation for recommendation, a rating r=4 is modelled as r^=p⊤q with user vector p=(1,0.5) and item vector q=(2,1). With squared loss plus L2 penalty 12λ(∥p∥2+∥q∥2), learning rate η=0.1 and λ=0.1, perform one stochastic gradient step on this rating. What are the new p, q and prediction?