Principal Component Analysis

Principal component analysis (PCA) finds the orthogonal directions along which a data set varies most. It describes each sample by its coordinates along the top of them. Stack samples as the rows of , and subtract the mean sample from every row. From here on, denotes this centered matrix. Its sample covariance and its SVD are

with singular values , left singular vectors and right singular vectors . PCA reads everything off these two factorizations:

  • Principal directions (loadings): the columns of . They are orthonormal eigenvectors of with eigenvalues .
  • Variance along : . The total variance is .
  • Scores: , where . Row is the code of sample , with entries .
  • Reconstruction: for one sample. For the centered matrix it is .
  • Variance explained by component : . The first components explain the sum of their shares.

Two views lead to the same subspace, spanned by :

  • Maximum variance: . Each later maximizes the same quantity among unit vectors orthogonal to .
  • Minimum reconstruction error: minimizes over all with orthonormal columns. By the Eckart-Young theorem, the minimum is .

There are three common rules for choosing . The first looks for the elbow of a scree plot of against . The second keeps enough components for a target share of variance, such as or . The third validates on a later task. Features in different units should be standardized first, which makes the correlation matrix. Each is unique up to sign when the are distinct. A linear autoencoder with a -dimensional code and squared loss learns the same subspace, possibly in a different basis.

Rows Versus Columns

The Mathematics notes 13.1 Singular Value Decomposition and 13.3 Low-Rank Approximation state their results for a general matrix . They write plain capitals and arrow vectors such as . To apply them here, set . Their is then the sample count , and their is the feature count . Many linear algebra texts instead store data points as the columns of . Then , the principal directions are the left singular vectors of the centered , and the covariance is . Some texts also divide by instead of . The directions stay the same, and every scales by .

Not Taught in Lecture

Lecture 14 defined PCA as projection onto the top right singular vectors of . It linked PCA to the Eckart-Young theorem and to linear autoencoders. The covariance and maximum-variance view, variance explained, choosing and standardizing are not from the lecture. Neither are the properties and the derivation below. They follow ISLR section 12.2 (James, Witten, Hastie and Tibshirani) and Bishop’s PRML section 12.1.

Intuition

The name describes the output. The principal components are the main directions in which the data vary. Picture a cloud of points in dimensions. Draw the line through its center along which the points spread the most. That line is the first principal direction. The second is the direction of greatest spread perpendicular to the first, and so on. Projecting each point onto the first few directions keeps most of its position with far fewer numbers. The dropped directions carry little spread, so little is lost when most of the variance sits in a few directions.

Each centered point splits into a part inside the kept subspace and a residual perpendicular to it. By Pythagoras, the squared length of the point is the sum of the squared lengths of the two parts. The data fix the total. Keeping more variance in the subspace therefore leaves less in the residuals. This is why the maximum-variance view and the minimum-error view pick the same directions.

The animation projects 30 points onto the plane of the top two principal directions. The sticks are the residuals, and their squared lengths sum to . The bars show each direction’s share of the variance.

\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\newcommand{\pf}[1]{\filldraw[draw=black, fill=cold] (#1) circle (2.5pt);}
\newcommand{\ph}[1]{\draw[cold, thick] (#1) circle (2.3pt);}
\newcommand{\gh}[1]{\draw[cold] (#1) circle (1.5pt);}
\newcommand{\rs}[2]{\draw (#1) -- (#2);}
\newcommand{\rd}[2]{\draw[dashed] (#1) -- (#2);}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\filldraw[draw=black, fill=hot] (8.95,0.0) rectangle (9.65,2.17);
\node[anchor=south] at (9.30,2.17) {$72.4\%$};
\node[anchor=north] at (9.30,-0.05) {$\mathbf v_1$};
\filldraw[draw=black, fill=hot] (10.00,0.0) rectangle (10.70,0.69);
\node[anchor=south] at (10.35,0.69) {$23.0\%$};
\node[anchor=north] at (10.35,-0.05) {$\mathbf v_2$};
\filldraw[draw=black, fill=mid] (11.05,0.0) rectangle (11.75,0.14);
\node[anchor=south] at (11.40,0.14) {$4.6\%$};
\node[anchor=north] at (11.40,-0.05) {$\mathbf v_3$};
\draw (8.70,0.0) -- (12.00,0.0);
\node[anchor=west] at (8.60,3.75) {variance explained};
\node[anchor=west] at (8.60,3.25) {\footnotesize $\sigma_j^2 / (\sigma_1^2 + \sigma_2^2 + \sigma_3^2)$};
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 12.46s = "true", 15.46s = "false", 20.54s = "false", repeats}}}]
\node[anchor=west] at (8.60,-0.80) {\footnotesize lost: $\mathbf v_3$, $4.6\%$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 17.14s = "true", 20.54s = "true", repeats}}}]
\node[anchor=west] at (8.60,-0.80) {\footnotesize kept: $\mathbf v_1, \mathbf v_2$, $95.4\%$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.4s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (0.00,1.33) -- (5.82,1.60);
\draw[mid, dashed] (7.60,1.31) -- (5.82,1.60);
\draw[mid, dashed] (5.82,1.60) -- (5.82,3.07);
\pf{4.53,1.83}
\pf{4.67,1.98}
\pf{5.36,2.28}
\pf{6.66,2.56}
\pf{3.89,2.15}
\pf{4.71,2.65}
\pf{2.53,1.86}
\pf{2.43,1.64}
\pf{5.18,2.22}
\pf{5.87,2.39}
\pf{4.66,1.74}
\pf{4.38,2.73}
\pf{2.43,2.32}
\pf{3.89,2.11}
\pf{2.33,2.35}
\pf{2.58,2.30}
\pf{4.11,1.56}
\pf{3.88,1.83}
\pf{4.77,1.59}
\pf{2.48,1.88}
\pf{3.58,2.17}
\pf{4.13,1.35}
\pf{1.36,2.25}
\pf{3.79,1.60}
\pf{4.26,1.98}
\pf{4.21,2.06}
\pf{1.85,2.28}
\pf{3.56,1.95}
\pf{3.15,1.75}
\pf{2.79,2.32}
\draw[mid] (1.78,1.04) -- (7.60,1.31);
\draw[mid] (1.78,2.51) -- (7.60,2.78);
\draw[mid] (0.00,2.80) -- (5.82,3.07);
\draw[mid] (1.78,1.04) -- (0.00,1.33);
\draw[mid] (1.78,2.51) -- (0.00,2.80);
\draw[mid] (7.60,2.78) -- (5.82,3.07);
\draw[mid] (1.78,1.04) -- (1.78,2.51);
\draw[mid] (0.00,1.33) -- (0.00,2.80);
\draw[mid] (7.60,1.31) -- (7.60,2.78);
 
\node[anchor=west] at (-0.1,-1.45) {Seen edge-on, $30$ centered points form a thin slab.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.4s = "true", 2.66s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (0.01,1.36) -- (5.95,1.70);
\draw[mid, dashed] (7.59,1.29) -- (5.95,1.70);
\draw[mid, dashed] (5.95,1.70) -- (5.95,3.16);
\pf{4.62,1.90}
\pf{4.72,2.02}
\pf{5.41,2.31}
\pf{3.93,2.19}
\pf{6.71,2.59}
\pf{2.56,1.90}
\pf{4.76,2.68}
\pf{2.45,1.66}
\pf{5.20,2.23}
\pf{5.88,2.39}
\pf{4.66,1.74}
\pf{2.43,2.33}
\pf{4.39,2.73}
\pf{2.33,2.35}
\pf{3.89,2.11}
\pf{2.58,2.30}
\pf{4.10,1.56}
\pf{3.87,1.83}
\pf{2.46,1.87}
\pf{4.75,1.57}
\pf{3.55,2.16}
\pf{1.34,2.24}
\pf{4.10,1.33}
\pf{3.76,1.58}
\pf{4.23,1.95}
\pf{1.82,2.26}
\pf{4.17,2.03}
\pf{3.51,1.91}
\pf{3.09,1.71}
\pf{2.73,2.28}
\draw[mid] (1.65,0.95) -- (7.59,1.29);
\draw[mid] (1.65,2.41) -- (7.59,2.75);
\draw[mid] (0.01,2.82) -- (5.95,3.16);
\draw[mid] (1.65,0.95) -- (0.01,1.36);
\draw[mid] (1.65,2.41) -- (0.01,2.82);
\draw[mid] (7.59,2.75) -- (5.95,3.16);
\draw[mid] (1.65,0.95) -- (1.65,2.41);
\draw[mid] (0.01,1.36) -- (0.01,2.82);
\draw[mid] (7.59,1.29) -- (7.59,2.75);
 
\node[anchor=west] at (-0.1,-1.45) {From higher up, the slab is long in one direction and shorter in the other.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.66s = "true", 2.92s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (0.06,1.47) -- (6.27,1.92);
\draw[mid, dashed] (7.54,1.20) -- (6.27,1.92);
\draw[mid, dashed] (6.27,1.92) -- (6.27,3.36);
\pf{4.86,2.07}
\pf{4.84,2.10}
\pf{4.05,2.28}
\pf{2.67,2.00}
\pf{5.52,2.37}
\pf{4.85,2.73}
\pf{2.51,1.74}
\pf{6.81,2.61}
\pf{2.46,2.37}
\pf{4.68,1.74}
\pf{5.23,2.23}
\pf{2.34,2.38}
\pf{5.90,2.37}
\pf{2.58,2.32}
\pf{4.40,2.73}
\pf{3.89,2.10}
\pf{4.08,1.54}
\pf{3.85,1.82}
\pf{2.42,1.86}
\pf{1.29,2.24}
\pf{4.69,1.52}
\pf{3.50,2.12}
\pf{1.75,2.24}
\pf{4.03,1.27}
\pf{3.68,1.53}
\pf{4.15,1.88}
\pf{4.08,1.95}
\pf{3.38,1.82}
\pf{2.95,1.61}
\pf{2.59,2.18}
\draw[mid] (1.33,0.76) -- (7.54,1.20);
\draw[mid] (1.33,2.20) -- (7.54,2.64);
\draw[mid] (0.06,2.91) -- (6.27,3.36);
\draw[mid] (1.33,0.76) -- (0.06,1.47);
\draw[mid] (1.33,2.20) -- (0.06,2.91);
\draw[mid] (7.54,2.64) -- (6.27,3.36);
\draw[mid] (1.33,0.76) -- (1.33,2.20);
\draw[mid] (0.06,1.47) -- (0.06,2.91);
\draw[mid] (7.54,1.20) -- (7.54,2.64);
 
\node[anchor=west] at (-0.1,-1.45) {From higher up, the slab is long in one direction and shorter in the other.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.92s = "true", 3.18s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (0.19,1.73) -- (6.65,2.13);
\draw[mid, dashed] (7.41,0.99) -- (6.65,2.13);
\draw[mid, dashed] (6.65,2.13) -- (6.65,3.53);
\pf{5.16,2.27}
\pf{2.83,2.17}
\pf{4.21,2.39}
\pf{4.98,2.18}
\pf{2.62,1.88}
\pf{5.65,2.40}
\pf{4.97,2.76}
\pf{2.51,2.45}
\pf{2.38,2.46}
\pf{6.89,2.55}
\pf{2.60,2.37}
\pf{4.68,1.72}
\pf{1.27,2.31}
\pf{5.24,2.18}
\pf{3.88,2.09}
\pf{2.39,1.89}
\pf{4.04,1.52}
\pf{3.83,1.80}
\pf{4.42,2.70}
\pf{5.89,2.28}
\pf{1.70,2.27}
\pf{3.43,2.07}
\pf{3.92,1.20}
\pf{4.59,1.42}
\pf{3.57,1.46}
\pf{4.03,1.78}
\pf{3.96,1.84}
\pf{2.76,1.50}
\pf{3.20,1.70}
\pf{2.42,2.09}
\draw[mid] (0.95,0.58) -- (7.41,0.99);
\draw[mid] (0.95,1.98) -- (7.41,2.39);
\draw[mid] (0.19,3.13) -- (6.65,3.53);
\draw[mid] (0.95,0.58) -- (0.19,1.73);
\draw[mid] (0.95,1.98) -- (0.19,3.13);
\draw[mid] (7.41,2.39) -- (6.65,3.53);
\draw[mid] (0.95,0.58) -- (0.95,1.98);
\draw[mid] (0.19,1.73) -- (0.19,3.13);
\draw[mid] (7.41,0.99) -- (7.41,2.39);
 
\node[anchor=west] at (-0.1,-1.45) {From higher up, the slab is long in one direction and shorter in the other.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.18s = "true", 3.44s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (0.42,2.13) -- (7.01,2.25);
\draw[mid, dashed] (7.18,0.65) -- (7.01,2.25);
\draw[mid, dashed] (7.01,2.25) -- (7.01,3.59);
\pf{5.45,2.42}
\pf{3.03,2.38}
\pf{2.76,2.06}
\pf{4.37,2.48}
\pf{5.12,2.21}
\pf{2.61,2.58}
\pf{2.46,2.58}
\pf{5.74,2.35}
\pf{1.31,2.47}
\pf{2.65,2.46}
\pf{5.06,2.74}
\pf{2.39,1.98}
\pf{4.67,1.68}
\pf{1.69,2.37}
\pf{4.00,1.49}
\pf{3.87,2.08}
\pf{3.80,1.79}
\pf{5.22,2.08}
\pf{6.91,2.37}
\pf{4.42,2.63}
\pf{3.80,1.14}
\pf{3.36,2.04}
\pf{3.46,1.42}
\pf{4.46,1.31}
\pf{5.83,2.10}
\pf{3.89,1.67}
\pf{3.81,1.73}
\pf{2.58,1.45}
\pf{2.26,2.04}
\pf{3.02,1.61}
\draw[mid] (0.59,0.53) -- (7.18,0.65);
\draw[mid] (0.59,1.86) -- (7.18,1.98);
\draw[mid] (0.42,3.46) -- (7.01,3.59);
\draw[mid] (0.59,0.53) -- (0.42,2.13);
\draw[mid] (0.59,1.86) -- (0.42,3.46);
\draw[mid] (7.18,1.98) -- (7.01,3.59);
\draw[mid] (0.59,0.53) -- (0.59,1.86);
\draw[mid] (0.42,2.13) -- (0.42,3.46);
\draw[mid] (7.18,0.65) -- (7.18,1.98);
 
\node[anchor=west] at (-0.1,-1.45) {From higher up, the slab is long in one direction and shorter in the other.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.44s = "true", 3.7s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (0.71,2.58) -- (7.27,2.24);
\draw[mid, dashed] (0.33,0.61) -- (0.71,2.58);
\draw[mid, dashed] (0.71,2.58) -- (0.71,3.84);
\pf{5.69,2.49}
\pf{3.23,2.58}
\pf{2.92,2.26}
\pf{4.51,2.53}
\pf{2.72,2.72}
\pf{5.21,2.19}
\pf{1.40,2.68}
\pf{2.56,2.72}
\pf{2.72,2.58}
\pf{2.41,2.10}
\pf{1.72,2.52}
\pf{5.79,2.25}
\pf{5.13,2.67}
\pf{3.95,1.47}
\pf{3.77,1.78}
\pf{4.63,1.61}
\pf{3.86,2.06}
\pf{3.69,1.10}
\pf{3.36,1.40}
\pf{3.30,2.02}
\pf{5.17,1.94}
\pf{4.40,2.55}
\pf{4.34,1.20}
\pf{2.44,1.45}
\pf{6.86,2.10}
\pf{3.77,1.58}
\pf{2.15,2.05}
\pf{3.68,1.64}
\pf{2.88,1.57}
\pf{5.73,1.88}
\draw[mid] (0.33,0.61) -- (6.89,0.27);
\draw[mid] (0.33,1.87) -- (6.89,1.53);
\draw[mid] (0.71,3.84) -- (7.27,3.50);
\draw[mid] (0.33,1.87) -- (0.71,3.84);
\draw[mid] (6.89,0.27) -- (7.27,2.24);
\draw[mid] (6.89,1.53) -- (7.27,3.50);
\draw[mid] (0.33,0.61) -- (0.33,1.87);
\draw[mid] (6.89,0.27) -- (6.89,1.53);
\draw[mid] (7.27,2.24) -- (7.27,3.50);
 
\node[anchor=west] at (-0.1,-1.45) {From higher up, the slab is long in one direction and shorter in the other.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.7s = "true", 3.96s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (0.96,2.95) -- (7.41,2.16);
\draw[mid, dashed] (0.19,0.76) -- (0.96,2.95);
\draw[mid, dashed] (0.96,2.95) -- (0.96,4.14);
\pf{3.38,2.72}
\pf{5.84,2.49}
\pf{3.04,2.41}
\pf{1.49,2.87}
\pf{4.60,2.55}
\pf{2.81,2.83}
\pf{2.64,2.84}
\pf{2.45,2.21}
\pf{5.26,2.15}
\pf{2.79,2.67}
\pf{1.78,2.66}
\pf{3.92,1.47}
\pf{3.75,1.78}
\pf{3.85,2.05}
\pf{5.79,2.13}
\pf{4.60,1.56}
\pf{5.16,2.59}
\pf{3.61,1.09}
\pf{3.30,1.40}
\pf{3.27,2.02}
\pf{2.36,1.48}
\pf{4.23,1.13}
\pf{5.12,1.82}
\pf{4.39,2.47}
\pf{2.10,2.10}
\pf{2.79,1.56}
\pf{3.68,1.53}
\pf{3.59,1.59}
\pf{6.78,1.86}
\pf{5.63,1.70}
\draw[mid] (0.19,0.76) -- (6.64,-0.03);
\draw[mid] (0.19,1.95) -- (6.64,1.16);
\draw[mid] (0.96,4.14) -- (7.41,3.35);
\draw[mid] (0.19,1.95) -- (0.96,4.14);
\draw[mid] (6.64,-0.03) -- (7.41,2.16);
\draw[mid] (6.64,1.16) -- (7.41,3.35);
\draw[mid] (0.19,0.76) -- (0.19,1.95);
\draw[mid] (6.64,-0.03) -- (6.64,1.16);
\draw[mid] (7.41,2.16) -- (7.41,3.35);
 
\node[anchor=west] at (-0.1,-1.45) {From higher up, the slab is long in one direction and shorter in the other.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.96s = "true", 5.36s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (1.06,3.10) -- (7.46,2.12);
\draw[mid, dashed] (0.14,0.84) -- (1.06,3.10);
\draw[mid, dashed] (1.06,3.10) -- (1.06,4.26);
\pf{3.44,2.77}
\pf{3.09,2.47}
\pf{5.89,2.48}
\pf{1.54,2.95}
\pf{4.64,2.55}
\pf{2.85,2.88}
\pf{2.68,2.88}
\pf{2.47,2.26}
\pf{2.82,2.71}
\pf{5.27,2.12}
\pf{1.81,2.72}
\pf{3.90,1.46}
\pf{3.75,1.78}
\pf{3.85,2.05}
\pf{4.58,1.53}
\pf{5.79,2.08}
\pf{3.58,1.09}
\pf{5.16,2.55}
\pf{3.28,1.41}
\pf{3.26,2.03}
\pf{2.33,1.50}
\pf{4.19,1.10}
\pf{2.08,2.12}
\pf{4.38,2.44}
\pf{5.09,1.77}
\pf{2.75,1.57}
\pf{3.64,1.51}
\pf{3.55,1.57}
\pf{6.75,1.75}
\pf{5.59,1.62}
\draw[mid] (0.14,0.84) -- (6.54,-0.15);
\draw[mid] (0.14,2.00) -- (6.54,1.01);
\draw[mid] (1.06,4.26) -- (7.46,3.28);
\draw[mid] (0.14,2.00) -- (1.06,4.26);
\draw[mid] (6.54,-0.15) -- (7.46,2.12);
\draw[mid] (6.54,1.01) -- (7.46,3.28);
\draw[mid] (0.14,0.84) -- (0.14,2.00);
\draw[mid] (6.54,-0.15) -- (6.54,1.01);
\draw[mid] (7.46,2.12) -- (7.46,3.28);
 
\node[anchor=west] at (-0.1,-1.45) {From higher up, the slab is long in one direction and shorter in the other.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.36s = "true", 5.58s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (1.06,3.10) -- (7.46,2.12);
\draw[mid, dashed] (0.14,0.84) -- (1.06,3.10);
\draw[mid, dashed] (1.06,3.10) -- (1.06,4.26);
\pf{3.44,2.77}
\pf{3.09,2.47}
\pf{5.89,2.48}
\pf{1.54,2.95}
\pf{4.64,2.55}
\pf{2.85,2.88}
\pf{2.68,2.88}
\pf{2.47,2.26}
\pf{2.82,2.71}
\pf{5.27,2.12}
\pf{1.81,2.72}
\draw[->, hot, very thick] (3.80,2.06) -- (3.92,2.36);
\pf{3.90,1.46}
\pf{3.75,1.78}
\pf{3.85,2.05}
\pf{4.58,1.53}
\draw[->, hot, very thick] (3.80,2.06) -- (4.68,1.92);
\pf{5.79,2.08}
\pf{3.58,1.09}
\pf{5.16,2.55}
\pf{3.28,1.41}
\pf{3.26,2.03}
\pf{2.33,1.50}
\pf{4.19,1.10}
\pf{2.08,2.12}
\pf{4.38,2.44}
\pf{5.09,1.77}
\pf{2.75,1.57}
\pf{3.64,1.51}
\pf{3.55,1.57}
\pf{6.75,1.75}
\pf{5.59,1.62}
\draw[mid] (0.14,0.84) -- (6.54,-0.15);
\draw[mid] (0.14,2.00) -- (6.54,1.01);
\draw[mid] (1.06,4.26) -- (7.46,3.28);
\draw[mid] (0.14,2.00) -- (1.06,4.26);
\draw[mid] (6.54,-0.15) -- (7.46,2.12);
\draw[mid] (6.54,1.01) -- (7.46,3.28);
\draw[mid] (0.14,0.84) -- (0.14,2.00);
\draw[mid] (6.54,-0.15) -- (6.54,1.01);
\draw[mid] (7.46,2.12) -- (7.46,3.28);
 
\node[anchor=west] at (-0.1,-1.45) {The principal directions $\mathbf v_j$ are the columns of $\mathbf V$ in $\mathbf X = \mathbf U\Sigma\mathbf V^T$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.58s = "true", 5.8s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (1.06,3.10) -- (7.46,2.12);
\draw[mid, dashed] (0.14,0.84) -- (1.06,3.10);
\draw[mid, dashed] (1.06,3.10) -- (1.06,4.26);
\pf{3.44,2.77}
\pf{3.09,2.47}
\pf{5.89,2.48}
\pf{1.54,2.95}
\pf{4.64,2.55}
\pf{2.85,2.88}
\pf{2.68,2.88}
\pf{2.47,2.26}
\pf{2.82,2.71}
\pf{5.27,2.12}
\pf{1.81,2.72}
\draw[->, hot, very thick] (3.80,2.06) -- (4.05,2.67);
\pf{3.90,1.46}
\pf{3.75,1.78}
\pf{3.85,2.05}
\pf{4.58,1.53}
\pf{5.79,2.08}
\pf{3.58,1.09}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.41);
\pf{5.16,2.55}
\pf{3.28,1.41}
\draw[->, hot, very thick] (3.80,2.06) -- (5.56,1.79);
\pf{3.26,2.03}
\pf{2.33,1.50}
\pf{4.19,1.10}
\pf{2.08,2.12}
\pf{4.38,2.44}
\pf{5.09,1.77}
\pf{2.75,1.57}
\pf{3.64,1.51}
\pf{3.55,1.57}
\pf{6.75,1.75}
\pf{5.59,1.62}
\draw[mid] (0.14,0.84) -- (6.54,-0.15);
\draw[mid] (0.14,2.00) -- (6.54,1.01);
\draw[mid] (1.06,4.26) -- (7.46,3.28);
\draw[mid] (0.14,2.00) -- (1.06,4.26);
\draw[mid] (6.54,-0.15) -- (7.46,2.12);
\draw[mid] (6.54,1.01) -- (7.46,3.28);
\draw[mid] (0.14,0.84) -- (0.14,2.00);
\draw[mid] (6.54,-0.15) -- (6.54,1.01);
\draw[mid] (7.46,2.12) -- (7.46,3.28);
 
\node[anchor=west] at (-0.1,-1.45) {The principal directions $\mathbf v_j$ are the columns of $\mathbf V$ in $\mathbf X = \mathbf U\Sigma\mathbf V^T$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.8s = "true", 6.02s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (1.06,3.10) -- (7.46,2.12);
\draw[mid, dashed] (0.14,0.84) -- (1.06,3.10);
\draw[mid, dashed] (1.06,3.10) -- (1.06,4.26);
\pf{3.44,2.77}
\pf{3.09,2.47}
\pf{5.89,2.48}
\pf{1.54,2.95}
\pf{4.64,2.55}
\pf{2.85,2.88}
\pf{2.68,2.88}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\pf{2.47,2.26}
\pf{2.82,2.71}
\pf{5.27,2.12}
\pf{1.81,2.72}
\pf{3.90,1.46}
\pf{3.75,1.78}
\pf{3.85,2.05}
\pf{4.58,1.53}
\pf{5.79,2.08}
\pf{3.58,1.09}
\pf{5.16,2.55}
\pf{3.28,1.41}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\pf{3.26,2.03}
\pf{2.33,1.50}
\pf{4.19,1.10}
\pf{2.08,2.12}
\pf{4.38,2.44}
\pf{5.09,1.77}
\pf{2.75,1.57}
\pf{3.64,1.51}
\pf{3.55,1.57}
\pf{6.75,1.75}
\pf{5.59,1.62}
\draw[mid] (0.14,0.84) -- (6.54,-0.15);
\draw[mid] (0.14,2.00) -- (6.54,1.01);
\draw[mid] (1.06,4.26) -- (7.46,3.28);
\draw[mid] (0.14,2.00) -- (1.06,4.26);
\draw[mid] (6.54,-0.15) -- (7.46,2.12);
\draw[mid] (6.54,1.01) -- (7.46,3.28);
\draw[mid] (0.14,0.84) -- (0.14,2.00);
\draw[mid] (6.54,-0.15) -- (6.54,1.01);
\draw[mid] (7.46,2.12) -- (7.46,3.28);
\node[fill=white, inner sep=1pt] at (6.43,1.40) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.80,3.07) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {The principal directions $\mathbf v_j$ are the columns of $\mathbf V$ in $\mathbf X = \mathbf U\Sigma\mathbf V^T$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.02s = "true", 8.82s = "false", 20.54s = "false", repeats}}}]
\draw[mid, dashed] (1.06,3.10) -- (7.46,2.12);
\draw[mid, dashed] (0.14,0.84) -- (1.06,3.10);
\draw[mid, dashed] (1.06,3.10) -- (1.06,4.26);
\pf{3.44,2.77}
\pf{3.09,2.47}
\pf{5.89,2.48}
\pf{1.54,2.95}
\pf{4.64,2.55}
\pf{2.85,2.88}
\pf{2.68,2.88}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\pf{2.47,2.26}
\pf{2.82,2.71}
\pf{5.27,2.12}
\pf{1.81,2.72}
\pf{3.90,1.46}
\pf{3.75,1.78}
\pf{3.85,2.05}
\pf{4.58,1.53}
\pf{5.79,2.08}
\pf{3.58,1.09}
\pf{5.16,2.55}
\pf{3.28,1.41}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\pf{3.26,2.03}
\pf{2.33,1.50}
\pf{4.19,1.10}
\pf{2.08,2.12}
\pf{4.38,2.44}
\pf{5.09,1.77}
\pf{2.75,1.57}
\pf{3.64,1.51}
\pf{3.55,1.57}
\pf{6.75,1.75}
\pf{5.59,1.62}
\draw[mid] (0.14,0.84) -- (6.54,-0.15);
\draw[mid] (0.14,2.00) -- (6.54,1.01);
\draw[mid] (1.06,4.26) -- (7.46,3.28);
\draw[mid] (0.14,2.00) -- (1.06,4.26);
\draw[mid] (6.54,-0.15) -- (7.46,2.12);
\draw[mid] (6.54,1.01) -- (7.46,3.28);
\draw[mid] (0.14,0.84) -- (0.14,2.00);
\draw[mid] (6.54,-0.15) -- (6.54,1.01);
\draw[mid] (7.46,2.12) -- (7.46,3.28);
\node[fill=white, inner sep=1pt] at (6.43,1.40) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.80,3.07) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Arrow lengths are proportional to the singular values $\sigma_j$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.82s = "true", 11.02s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\ph{3.44,2.77}
\ph{3.09,2.47}
\ph{5.89,2.48}
\ph{4.64,2.55}
\ph{2.47,2.26}
\ph{5.27,2.12}
\ph{3.90,1.46}
\ph{3.75,1.78}
\ph{4.58,1.53}
\ph{3.58,1.09}
\ph{3.28,1.41}
\ph{2.33,1.50}
\ph{4.19,1.10}
\ph{3.64,1.51}
\pf{1.54,2.95}
\pf{2.85,2.88}
\pf{2.68,2.88}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\pf{2.82,2.71}
\pf{1.81,2.72}
\pf{3.85,2.05}
\pf{5.79,2.08}
\pf{5.16,2.55}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\pf{3.26,2.03}
\pf{2.08,2.12}
\pf{4.38,2.44}
\pf{5.09,1.77}
\pf{2.75,1.57}
\pf{3.55,1.57}
\pf{6.75,1.75}
\pf{5.59,1.62}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Keep $k = 2$ directions: the plane spanned by $\mathbf v_1$ and $\mathbf v_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.02s = "true", 11.26s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\rd{3.44,2.77}{3.44,2.78}\gh{3.44,2.77}
\ph{3.44,2.78}
\rd{3.09,2.47}{3.09,2.49}\gh{3.09,2.47}
\ph{3.09,2.49}
\rd{5.89,2.48}{5.89,2.50}\gh{5.89,2.48}
\ph{5.89,2.50}
\rd{4.64,2.55}{4.64,2.55}\gh{4.64,2.55}
\ph{4.64,2.55}
\rd{2.47,2.26}{2.47,2.27}\gh{2.47,2.26}
\ph{2.47,2.27}
\rd{5.27,2.12}{5.27,2.13}\gh{5.27,2.12}
\ph{5.27,2.13}
\rd{3.90,1.46}{3.90,1.48}\gh{3.90,1.46}
\ph{3.90,1.48}
\rd{3.75,1.78}{3.75,1.79}\gh{3.75,1.78}
\ph{3.75,1.79}
\rd{4.58,1.53}{4.58,1.55}\gh{4.58,1.53}
\ph{4.58,1.55}
\rd{3.58,1.09}{3.58,1.11}\gh{3.58,1.09}
\ph{3.58,1.11}
\rd{3.28,1.41}{3.28,1.42}\gh{3.28,1.41}
\ph{3.28,1.42}
\rd{2.33,1.50}{2.33,1.51}\gh{2.33,1.50}
\ph{2.33,1.51}
\rd{4.19,1.10}{4.19,1.12}\gh{4.19,1.10}
\ph{4.19,1.12}
\rd{3.64,1.51}{3.64,1.51}\gh{3.64,1.51}
\ph{3.64,1.51}
\rs{1.54,2.95}{1.54,2.94}\gh{1.54,2.95}\pf{1.54,2.94}
\rs{2.85,2.88}{2.85,2.86}\gh{2.85,2.88}\pf{2.85,2.86}
\rs{2.68,2.88}{2.68,2.87}\gh{2.68,2.88}\pf{2.68,2.87}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\rs{2.82,2.71}{2.82,2.70}\gh{2.82,2.71}\pf{2.82,2.70}
\rs{1.81,2.72}{1.81,2.71}\gh{1.81,2.72}\pf{1.81,2.71}
\rs{3.85,2.05}{3.85,2.05}\gh{3.85,2.05}\pf{3.85,2.05}
\rs{5.79,2.08}{5.79,2.07}\gh{5.79,2.08}\pf{5.79,2.07}
\rs{5.16,2.55}{5.16,2.52}\gh{5.16,2.55}\pf{5.16,2.52}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\rs{3.26,2.03}{3.26,2.02}\gh{3.26,2.03}\pf{3.26,2.02}
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\rs{2.08,2.12}{2.08,2.10}\gh{2.08,2.12}\pf{2.08,2.10}
\rs{4.38,2.44}{4.38,2.41}\gh{4.38,2.44}\pf{4.38,2.41}
\rs{5.09,1.77}{5.09,1.77}\gh{5.09,1.77}\pf{5.09,1.77}
\rs{2.75,1.57}{2.75,1.57}\gh{2.75,1.57}\pf{2.75,1.57}
\rs{3.55,1.57}{3.55,1.56}\gh{3.55,1.57}\pf{3.55,1.56}
\rs{6.75,1.75}{6.75,1.74}\gh{6.75,1.75}\pf{6.75,1.74}
\rs{5.59,1.62}{5.59,1.61}\gh{5.59,1.62}\pf{5.59,1.61}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Each point slides along $\mathbf v_3$ onto the plane. The sticks are the residuals.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.26s = "true", 11.5s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\rd{3.44,2.77}{3.44,2.81}\gh{3.44,2.77}
\ph{3.44,2.81}
\rd{3.09,2.47}{3.09,2.54}\gh{3.09,2.47}
\ph{3.09,2.54}
\rd{5.89,2.48}{5.89,2.54}\gh{5.89,2.48}
\ph{5.89,2.54}
\rd{4.64,2.55}{4.64,2.55}\gh{4.64,2.55}
\ph{4.64,2.55}
\rd{2.47,2.26}{2.47,2.28}\gh{2.47,2.26}
\ph{2.47,2.28}
\rd{5.27,2.12}{5.27,2.15}\gh{5.27,2.12}
\ph{5.27,2.15}
\rd{3.90,1.46}{3.90,1.54}\gh{3.90,1.46}
\ph{3.90,1.54}
\rd{3.75,1.78}{3.75,1.81}\gh{3.75,1.78}
\ph{3.75,1.81}
\rd{4.58,1.53}{4.58,1.59}\gh{4.58,1.53}
\ph{4.58,1.59}
\rd{3.28,1.41}{3.28,1.47}\gh{3.28,1.41}
\ph{3.28,1.47}
\rd{3.58,1.09}{3.58,1.19}\gh{3.58,1.09}
\ph{3.58,1.19}
\rd{2.33,1.50}{2.33,1.53}\gh{2.33,1.50}
\ph{2.33,1.53}
\rd{4.19,1.10}{4.19,1.17}\gh{4.19,1.10}
\ph{4.19,1.17}
\rd{3.64,1.51}{3.64,1.51}\gh{3.64,1.51}
\ph{3.64,1.51}
\rs{1.54,2.95}{1.54,2.91}\gh{1.54,2.95}\pf{1.54,2.91}
\rs{2.85,2.88}{2.85,2.84}\gh{2.85,2.88}\pf{2.85,2.84}
\rs{2.68,2.88}{2.68,2.84}\gh{2.68,2.88}\pf{2.68,2.84}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\rs{2.82,2.71}{2.82,2.67}\gh{2.82,2.71}\pf{2.82,2.67}
\rs{1.81,2.72}{1.81,2.68}\gh{1.81,2.72}\pf{1.81,2.68}
\rs{3.85,2.05}{3.85,2.04}\gh{3.85,2.05}\pf{3.85,2.04}
\rs{5.16,2.55}{5.16,2.47}\gh{5.16,2.55}\pf{5.16,2.47}
\rs{5.79,2.08}{5.79,2.06}\gh{5.79,2.08}\pf{5.79,2.06}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\rs{3.26,2.03}{3.26,2.00}\gh{3.26,2.03}\pf{3.26,2.00}
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\rs{4.38,2.44}{4.38,2.33}\gh{4.38,2.44}\pf{4.38,2.33}
\rs{2.08,2.12}{2.08,2.06}\gh{2.08,2.12}\pf{2.08,2.06}
\rs{5.09,1.77}{5.09,1.75}\gh{5.09,1.77}\pf{5.09,1.75}
\rs{2.75,1.57}{2.75,1.57}\gh{2.75,1.57}\pf{2.75,1.57}
\rs{3.55,1.57}{3.55,1.56}\gh{3.55,1.57}\pf{3.55,1.56}
\rs{6.75,1.75}{6.75,1.69}\gh{6.75,1.75}\pf{6.75,1.69}
\rs{5.59,1.62}{5.59,1.57}\gh{5.59,1.62}\pf{5.59,1.57}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Each point slides along $\mathbf v_3$ onto the plane. The sticks are the residuals.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.5s = "true", 11.74s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\rd{3.44,2.77}{3.44,2.85}\gh{3.44,2.77}
\ph{3.44,2.85}
\rd{3.09,2.47}{3.09,2.61}\gh{3.09,2.47}
\ph{3.09,2.61}
\rd{5.89,2.48}{5.89,2.61}\gh{5.89,2.48}
\ph{5.89,2.61}
\rd{4.64,2.55}{4.64,2.55}\gh{4.64,2.55}
\ph{4.64,2.55}
\rd{2.47,2.26}{2.47,2.30}\gh{2.47,2.26}
\ph{2.47,2.30}
\rd{5.27,2.12}{5.27,2.18}\gh{5.27,2.12}
\ph{5.27,2.18}
\rd{3.75,1.78}{3.75,1.85}\gh{3.75,1.78}
\ph{3.75,1.85}
\rd{3.90,1.46}{3.90,1.61}\gh{3.90,1.46}
\ph{3.90,1.61}
\rd{4.58,1.53}{4.58,1.64}\gh{4.58,1.53}
\ph{4.58,1.64}
\rd{3.28,1.41}{3.28,1.53}\gh{3.28,1.41}
\ph{3.28,1.53}
\rd{3.58,1.09}{3.58,1.29}\gh{3.58,1.09}
\ph{3.58,1.29}
\rd{2.33,1.50}{2.33,1.56}\gh{2.33,1.50}
\ph{2.33,1.56}
\rd{4.19,1.10}{4.19,1.23}\gh{4.19,1.10}
\ph{4.19,1.23}
\rd{3.64,1.51}{3.64,1.52}\gh{3.64,1.51}
\ph{3.64,1.52}
\rs{1.54,2.95}{1.54,2.87}\gh{1.54,2.95}\pf{1.54,2.87}
\rs{2.85,2.88}{2.85,2.80}\gh{2.85,2.88}\pf{2.85,2.80}
\rs{2.68,2.88}{2.68,2.79}\gh{2.68,2.88}\pf{2.68,2.79}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\rs{2.82,2.71}{2.82,2.63}\gh{2.82,2.71}\pf{2.82,2.63}
\rs{1.81,2.72}{1.81,2.63}\gh{1.81,2.72}\pf{1.81,2.63}
\rs{5.16,2.55}{5.16,2.39}\gh{5.16,2.55}\pf{5.16,2.39}
\rs{3.85,2.05}{3.85,2.03}\gh{3.85,2.05}\pf{3.85,2.03}
\rs{5.79,2.08}{5.79,2.04}\gh{5.79,2.08}\pf{5.79,2.04}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\rs{3.26,2.03}{3.26,1.97}\gh{3.26,2.03}\pf{3.26,1.97}
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\rs{4.38,2.44}{4.38,2.23}\gh{4.38,2.44}\pf{4.38,2.23}
\rs{2.08,2.12}{2.08,2.00}\gh{2.08,2.12}\pf{2.08,2.00}
\rs{5.09,1.77}{5.09,1.73}\gh{5.09,1.77}\pf{5.09,1.73}
\rs{2.75,1.57}{2.75,1.57}\gh{2.75,1.57}\pf{2.75,1.57}
\rs{3.55,1.57}{3.55,1.55}\gh{3.55,1.57}\pf{3.55,1.55}
\rs{6.75,1.75}{6.75,1.63}\gh{6.75,1.75}\pf{6.75,1.63}
\rs{5.59,1.62}{5.59,1.53}\gh{5.59,1.62}\pf{5.59,1.53}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Each point slides along $\mathbf v_3$ onto the plane. The sticks are the residuals.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.74s = "true", 11.98s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\rd{3.44,2.77}{3.44,2.90}\gh{3.44,2.77}
\ph{3.44,2.90}
\rd{3.09,2.47}{3.09,2.69}\gh{3.09,2.47}
\ph{3.09,2.69}
\rd{5.89,2.48}{5.89,2.68}\gh{5.89,2.48}
\ph{5.89,2.68}
\rd{4.64,2.55}{4.64,2.55}\gh{4.64,2.55}
\ph{4.64,2.55}
\rd{2.47,2.26}{2.47,2.32}\gh{2.47,2.26}
\ph{2.47,2.32}
\rd{5.27,2.12}{5.27,2.21}\gh{5.27,2.12}
\ph{5.27,2.21}
\rd{3.75,1.78}{3.75,1.88}\gh{3.75,1.78}
\ph{3.75,1.88}
\rd{3.90,1.46}{3.90,1.69}\gh{3.90,1.46}
\ph{3.90,1.69}
\rd{4.58,1.53}{4.58,1.70}\gh{4.58,1.53}
\ph{4.58,1.70}
\rd{3.28,1.41}{3.28,1.59}\gh{3.28,1.41}
\ph{3.28,1.59}
\rd{3.58,1.09}{3.58,1.40}\gh{3.58,1.09}
\ph{3.58,1.40}
\rd{2.33,1.50}{2.33,1.59}\gh{2.33,1.50}
\ph{2.33,1.59}
\rd{3.64,1.51}{3.64,1.52}\gh{3.64,1.51}
\ph{3.64,1.52}
\rd{4.19,1.10}{4.19,1.30}\gh{4.19,1.10}
\ph{4.19,1.30}
\rs{1.54,2.95}{1.54,2.83}\gh{1.54,2.95}\pf{1.54,2.83}
\rs{2.85,2.88}{2.85,2.75}\gh{2.85,2.88}\pf{2.85,2.75}
\rs{2.68,2.88}{2.68,2.74}\gh{2.68,2.88}\pf{2.68,2.74}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\rs{2.82,2.71}{2.82,2.59}\gh{2.82,2.71}\pf{2.82,2.59}
\rs{1.81,2.72}{1.81,2.58}\gh{1.81,2.72}\pf{1.81,2.58}
\rs{5.16,2.55}{5.16,2.30}\gh{5.16,2.55}\pf{5.16,2.30}
\rs{3.85,2.05}{3.85,2.02}\gh{3.85,2.05}\pf{3.85,2.02}
\rs{5.79,2.08}{5.79,2.02}\gh{5.79,2.08}\pf{5.79,2.02}
\rs{3.26,2.03}{3.26,1.95}\gh{3.26,2.03}\pf{3.26,1.95}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\rs{4.38,2.44}{4.38,2.12}\gh{4.38,2.44}\pf{4.38,2.12}
\rs{2.08,2.12}{2.08,1.93}\gh{2.08,2.12}\pf{2.08,1.93}
\rs{5.09,1.77}{5.09,1.71}\gh{5.09,1.77}\pf{5.09,1.71}
\rs{2.75,1.57}{2.75,1.56}\gh{2.75,1.57}\pf{2.75,1.56}
\rs{3.55,1.57}{3.55,1.53}\gh{3.55,1.57}\pf{3.55,1.53}
\rs{6.75,1.75}{6.75,1.56}\gh{6.75,1.75}\pf{6.75,1.56}
\rs{5.59,1.62}{5.59,1.47}\gh{5.59,1.62}\pf{5.59,1.47}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Each point slides along $\mathbf v_3$ onto the plane. The sticks are the residuals.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.98s = "true", 12.22s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\rd{3.44,2.77}{3.44,2.94}\gh{3.44,2.77}
\ph{3.44,2.94}
\rd{3.09,2.47}{3.09,2.76}\gh{3.09,2.47}
\ph{3.09,2.76}
\rd{5.89,2.48}{5.89,2.75}\gh{5.89,2.48}
\ph{5.89,2.75}
\rd{4.64,2.55}{4.64,2.55}\gh{4.64,2.55}
\ph{4.64,2.55}
\rd{2.47,2.26}{2.47,2.34}\gh{2.47,2.26}
\ph{2.47,2.34}
\rd{5.27,2.12}{5.27,2.24}\gh{5.27,2.12}
\ph{5.27,2.24}
\rd{3.75,1.78}{3.75,1.91}\gh{3.75,1.78}
\ph{3.75,1.91}
\rd{3.90,1.46}{3.90,1.77}\gh{3.90,1.46}
\ph{3.90,1.77}
\rd{4.58,1.53}{4.58,1.75}\gh{4.58,1.53}
\ph{4.58,1.75}
\rd{3.28,1.41}{3.28,1.65}\gh{3.28,1.41}
\ph{3.28,1.65}
\rd{2.33,1.50}{2.33,1.62}\gh{2.33,1.50}
\ph{2.33,1.62}
\rd{3.58,1.09}{3.58,1.50}\gh{3.58,1.09}
\ph{3.58,1.50}
\rd{3.64,1.51}{3.64,1.52}\gh{3.64,1.51}
\ph{3.64,1.52}
\rd{4.19,1.10}{4.19,1.37}\gh{4.19,1.10}
\ph{4.19,1.37}
\rs{1.54,2.95}{1.54,2.79}\gh{1.54,2.95}\pf{1.54,2.79}
\rs{2.85,2.88}{2.85,2.71}\gh{2.85,2.88}\pf{2.85,2.71}
\rs{2.68,2.88}{2.68,2.70}\gh{2.68,2.88}\pf{2.68,2.70}
\rs{2.82,2.71}{2.82,2.55}\gh{2.82,2.71}\pf{2.82,2.55}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\rs{1.81,2.72}{1.81,2.53}\gh{1.81,2.72}\pf{1.81,2.53}
\rs{5.16,2.55}{5.16,2.23}\gh{5.16,2.55}\pf{5.16,2.23}
\rs{3.85,2.05}{3.85,2.02}\gh{3.85,2.05}\pf{3.85,2.02}
\rs{5.79,2.08}{5.79,2.00}\gh{5.79,2.08}\pf{5.79,2.00}
\rs{3.26,2.03}{3.26,1.92}\gh{3.26,2.03}\pf{3.26,1.92}
\rs{4.38,2.44}{4.38,2.02}\gh{4.38,2.44}\pf{4.38,2.02}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\rs{2.08,2.12}{2.08,1.87}\gh{2.08,2.12}\pf{2.08,1.87}
\rs{5.09,1.77}{5.09,1.69}\gh{5.09,1.77}\pf{5.09,1.69}
\rs{2.75,1.57}{2.75,1.56}\gh{2.75,1.57}\pf{2.75,1.56}
\rs{3.55,1.57}{3.55,1.52}\gh{3.55,1.57}\pf{3.55,1.52}
\rs{6.75,1.75}{6.75,1.50}\gh{6.75,1.75}\pf{6.75,1.50}
\rs{5.59,1.62}{5.59,1.43}\gh{5.59,1.62}\pf{5.59,1.43}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Each point slides along $\mathbf v_3$ onto the plane. The sticks are the residuals.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 12.22s = "true", 12.46s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\rd{3.44,2.77}{3.44,2.97}\gh{3.44,2.77}
\ph{3.44,2.97}
\rd{3.09,2.47}{3.09,2.81}\gh{3.09,2.47}
\ph{3.09,2.81}
\rd{5.89,2.48}{5.89,2.80}\gh{5.89,2.48}
\ph{5.89,2.80}
\rd{4.64,2.55}{4.64,2.55}\gh{4.64,2.55}
\ph{4.64,2.55}
\rd{2.47,2.26}{2.47,2.36}\gh{2.47,2.26}
\ph{2.47,2.36}
\rd{5.27,2.12}{5.27,2.26}\gh{5.27,2.12}
\ph{5.27,2.26}
\rd{3.75,1.78}{3.75,1.94}\gh{3.75,1.78}
\ph{3.75,1.94}
\rd{3.90,1.46}{3.90,1.82}\gh{3.90,1.46}
\ph{3.90,1.82}
\rd{4.58,1.53}{4.58,1.79}\gh{4.58,1.53}
\ph{4.58,1.79}
\rd{3.28,1.41}{3.28,1.70}\gh{3.28,1.41}
\ph{3.28,1.70}
\rd{2.33,1.50}{2.33,1.64}\gh{2.33,1.50}
\ph{2.33,1.64}
\rd{3.58,1.09}{3.58,1.57}\gh{3.58,1.09}
\ph{3.58,1.57}
\rd{3.64,1.51}{3.64,1.52}\gh{3.64,1.51}
\ph{3.64,1.52}
\rd{4.19,1.10}{4.19,1.42}\gh{4.19,1.10}
\ph{4.19,1.42}
\rs{1.54,2.95}{1.54,2.76}\gh{1.54,2.95}\pf{1.54,2.76}
\rs{2.85,2.88}{2.85,2.68}\gh{2.85,2.88}\pf{2.85,2.68}
\rs{2.68,2.88}{2.68,2.66}\gh{2.68,2.88}\pf{2.68,2.66}
\rs{2.82,2.71}{2.82,2.52}\gh{2.82,2.71}\pf{2.82,2.52}
\rs{1.81,2.72}{1.81,2.50}\gh{1.81,2.72}\pf{1.81,2.50}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\rs{5.16,2.55}{5.16,2.17}\gh{5.16,2.55}\pf{5.16,2.17}
\rs{3.85,2.05}{3.85,2.01}\gh{3.85,2.05}\pf{3.85,2.01}
\rs{5.79,2.08}{5.79,1.99}\gh{5.79,2.08}\pf{5.79,1.99}
\rs{4.38,2.44}{4.38,1.95}\gh{4.38,2.44}\pf{4.38,1.95}
\rs{3.26,2.03}{3.26,1.90}\gh{3.26,2.03}\pf{3.26,1.90}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\rs{2.08,2.12}{2.08,1.83}\gh{2.08,2.12}\pf{2.08,1.83}
\rs{5.09,1.77}{5.09,1.67}\gh{5.09,1.77}\pf{5.09,1.67}
\rs{2.75,1.57}{2.75,1.56}\gh{2.75,1.57}\pf{2.75,1.56}
\rs{3.55,1.57}{3.55,1.51}\gh{3.55,1.57}\pf{3.55,1.51}
\rs{6.75,1.75}{6.75,1.46}\gh{6.75,1.75}\pf{6.75,1.46}
\rs{5.59,1.62}{5.59,1.39}\gh{5.59,1.62}\pf{5.59,1.39}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Each point slides along $\mathbf v_3$ onto the plane. The sticks are the residuals.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 12.46s = "true", 15.46s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.46,2.70) -- (1.06,3.68) -- (0.14,1.42) -- (6.54,0.43) -- cycle;
\draw[mid] (1.97,3.54) -- (1.06,1.27);
\draw[mid] (2.89,3.40) -- (1.97,1.13);
\draw[mid] (3.80,3.26) -- (2.88,0.99);
\draw[mid] (4.72,3.12) -- (3.80,0.85);
\draw[mid] (5.63,2.98) -- (4.71,0.71);
\draw[mid] (6.54,2.84) -- (5.63,0.57);
\draw[mid] (6.77,1.00) -- (0.37,1.98);
\draw[mid] (7.00,1.57) -- (0.60,2.55);
\draw[mid] (7.23,2.13) -- (0.83,3.11);
\rd{3.44,2.77}{3.44,2.98}\gh{3.44,2.77}
\rd{3.09,2.47}{3.09,2.83}\gh{3.09,2.47}
\rd{5.89,2.48}{5.89,2.82}\gh{5.89,2.48}
\rd{4.64,2.55}{4.64,2.55}\gh{4.64,2.55}
\rd{2.47,2.26}{2.47,2.36}\gh{2.47,2.26}
\rd{5.27,2.12}{5.27,2.27}\gh{5.27,2.12}
\rd{3.75,1.78}{3.75,1.95}\gh{3.75,1.78}
\rd{3.90,1.46}{3.90,1.84}\gh{3.90,1.46}
\rd{4.58,1.53}{4.58,1.80}\gh{4.58,1.53}
\rd{3.28,1.41}{3.28,1.71}\gh{3.28,1.41}
\rd{2.33,1.50}{2.33,1.65}\gh{2.33,1.50}
\rd{3.58,1.09}{3.58,1.60}\gh{3.58,1.09}
\rd{3.64,1.51}{3.64,1.52}\gh{3.64,1.51}
\rd{4.19,1.10}{4.19,1.44}\gh{4.19,1.10}
\pf{3.44,2.98}
\pf{3.09,2.83}
\pf{5.89,2.82}
\rs{1.54,2.95}{1.54,2.75}\gh{1.54,2.95}\pf{1.54,2.75}
\rs{2.85,2.88}{2.85,2.67}\gh{2.85,2.88}\pf{2.85,2.67}
\rs{2.68,2.88}{2.68,2.65}\gh{2.68,2.88}\pf{2.68,2.65}
\pf{4.64,2.55}
\rs{2.82,2.71}{2.82,2.51}\gh{2.82,2.71}\pf{2.82,2.51}
\rs{1.81,2.72}{1.81,2.49}\gh{1.81,2.72}\pf{1.81,2.49}
\draw[->, hot, very thick] (3.80,2.06) -- (4.17,2.97);
\pf{2.47,2.36}
\pf{5.27,2.27}
\rs{5.16,2.55}{5.16,2.15}\gh{5.16,2.55}\pf{5.16,2.15}
\rs{3.85,2.05}{3.85,2.01}\gh{3.85,2.05}\pf{3.85,2.01}
\rs{5.79,2.08}{5.79,1.98}\gh{5.79,2.08}\pf{5.79,1.98}
\pf{3.75,1.95}
\rs{4.38,2.44}{4.38,1.92}\gh{4.38,2.44}\pf{4.38,1.92}
\rs{3.26,2.03}{3.26,1.89}\gh{3.26,2.03}\pf{3.26,1.89}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.59);
\pf{3.90,1.84}
\draw[->, hot, very thick] (3.80,2.06) -- (6.43,1.65);
\rs{2.08,2.12}{2.08,1.81}\gh{2.08,2.12}\pf{2.08,1.81}
\pf{4.58,1.80}
\pf{3.28,1.71}
\rs{5.09,1.77}{5.09,1.67}\gh{5.09,1.77}\pf{5.09,1.67}
\pf{2.33,1.65}
\pf{3.58,1.60}
\rs{2.75,1.57}{2.75,1.56}\gh{2.75,1.57}\pf{2.75,1.56}
\pf{3.64,1.52}
\rs{3.55,1.57}{3.55,1.51}\gh{3.55,1.57}\pf{3.55,1.51}
\rs{6.75,1.75}{6.75,1.44}\gh{6.75,1.75}\pf{6.75,1.44}
\pf{4.19,1.44}
\rs{5.59,1.62}{5.59,1.38}\gh{5.59,1.62}\pf{5.59,1.38}
\node[fill=white, inner sep=1pt] at (6.28,1.36) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.49,2.97) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.50) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {Squared stick lengths sum to $\sigma_3^2 = 3.44$, the 4.6\% of variance that is lost.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 15.46s = "true", 15.7s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.45,2.75) -- (1.03,3.74) -- (0.15,1.36) -- (6.57,0.37) -- cycle;
\draw[mid] (1.95,3.60) -- (1.07,1.22);
\draw[mid] (2.87,3.46) -- (1.99,1.08);
\draw[mid] (3.78,3.32) -- (2.90,0.94);
\draw[mid] (4.70,3.18) -- (3.82,0.80);
\draw[mid] (5.61,3.04) -- (4.73,0.65);
\draw[mid] (6.53,2.90) -- (5.65,0.51);
\draw[mid] (6.79,0.97) -- (0.37,1.95);
\draw[mid] (7.01,1.56) -- (0.59,2.55);
\draw[mid] (7.23,2.16) -- (0.81,3.15);
\pf{3.43,3.03}
\pf{5.88,2.87}
\pf{3.08,2.86}
\pf{1.52,2.77}
\pf{2.84,2.70}
\pf{2.67,2.67}
\pf{4.63,2.58}
\pf{2.81,2.52}
\draw[->, hot, very thick] (3.80,2.06) -- (4.15,3.02);
\pf{1.80,2.50}
\pf{2.47,2.37}
\pf{5.27,2.29}
\pf{5.16,2.16}
\pf{3.85,2.00}
\pf{5.79,1.99}
\pf{3.75,1.94}
\pf{4.38,1.92}
\pf{3.26,1.88}
\pf{3.91,1.83}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.58);
\draw[->, hot, very thick] (3.80,2.06) -- (6.44,1.65);
\pf{4.58,1.80}
\pf{2.08,1.79}
\pf{3.28,1.69}
\pf{5.10,1.65}
\pf{2.33,1.62}
\pf{3.59,1.57}
\pf{2.76,1.53}
\pf{3.65,1.50}
\pf{3.56,1.48}
\pf{6.76,1.43}
\pf{4.20,1.41}
\pf{5.60,1.36}
\node[fill=white, inner sep=1pt] at (6.81,1.77) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.47,3.02) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.67) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {The plane turns to face us.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 15.7s = "true", 15.94s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.41,2.91) -- (0.96,3.88) -- (0.19,1.21) -- (6.64,0.23) -- cycle;
\draw[mid] (1.88,3.74) -- (1.11,1.07);
\draw[mid] (2.81,3.60) -- (2.03,0.93);
\draw[mid] (3.73,3.46) -- (2.95,0.79);
\draw[mid] (4.65,3.33) -- (3.87,0.65);
\draw[mid] (5.57,3.19) -- (4.79,0.51);
\draw[mid] (6.49,3.05) -- (5.72,0.37);
\draw[mid] (6.83,0.90) -- (0.38,1.87);
\draw[mid] (7.03,1.57) -- (0.57,2.54);
\draw[mid] (7.22,2.24) -- (0.77,3.21);
\pf{3.38,3.13}
\pf{5.84,3.00}
\pf{3.04,2.94}
\pf{1.49,2.81}
\pf{2.81,2.75}
\pf{2.65,2.72}
\pf{4.61,2.66}
\pf{2.79,2.56}
\draw[->, hot, very thick] (3.80,2.06) -- (4.11,3.14);
\pf{1.78,2.51}
\pf{2.45,2.38}
\pf{5.26,2.34}
\pf{5.16,2.20}
\pf{5.79,2.03}
\pf{3.85,2.00}
\pf{3.75,1.93}
\pf{4.39,1.91}
\pf{3.27,1.85}
\pf{3.91,1.81}
\draw[->, hot, very thick] (3.80,2.06) -- (6.46,1.66);
\pf{4.60,1.78}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.53);
\pf{2.09,1.72}
\pf{3.30,1.64}
\pf{5.11,1.63}
\pf{2.35,1.53}
\pf{3.61,1.51}
\pf{2.78,1.45}
\pf{3.67,1.43}
\pf{6.78,1.41}
\pf{3.59,1.41}
\pf{4.23,1.34}
\pf{5.63,1.31}
\node[fill=white, inner sep=1pt] at (6.75,1.75) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.43,3.14) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.63) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {The plane turns to face us.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 15.94s = "true", 16.18s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.37,3.13) -- (0.87,4.02) -- (0.23,0.98) -- (6.73,0.09) -- cycle;
\draw[mid] (1.79,3.90) -- (1.16,0.85);
\draw[mid] (2.72,3.77) -- (2.09,0.73);
\draw[mid] (3.65,3.64) -- (3.02,0.60);
\draw[mid] (4.58,3.51) -- (3.95,0.47);
\draw[mid] (5.51,3.39) -- (4.88,0.34);
\draw[mid] (6.44,3.26) -- (5.81,0.22);
\draw[mid] (6.89,0.85) -- (0.39,1.74);
\draw[mid] (7.05,1.61) -- (0.55,2.50);
\draw[mid] (7.21,2.37) -- (0.71,3.26);
\pf{3.33,3.25}
\pf{5.79,3.19}
\pf{3.00,3.03}
\pf{1.45,2.83}
\pf{2.78,2.81}
\pf{2.61,2.77}
\pf{4.57,2.76}
\draw[->, hot, very thick] (3.80,2.06) -- (4.05,3.28);
\pf{2.76,2.59}
\pf{1.76,2.50}
\pf{5.24,2.43}
\pf{2.44,2.38}
\pf{5.15,2.26}
\pf{5.79,2.09}
\pf{3.86,1.99}
\pf{4.39,1.91}
\pf{3.76,1.91}
\pf{3.28,1.81}
\draw[->, hot, very thick] (3.80,2.06) -- (6.48,1.69);
\pf{3.93,1.78}
\pf{4.61,1.77}
\pf{5.14,1.62}
\pf{2.11,1.62}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.45);
\pf{3.32,1.57}
\pf{3.64,1.44}
\pf{6.82,1.43}
\pf{2.38,1.42}
\pf{3.71,1.34}
\pf{2.82,1.34}
\pf{3.62,1.32}
\pf{5.67,1.28}
\pf{4.27,1.26}
\node[fill=white, inner sep=1pt] at (6.77,1.79) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.37,3.28) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.55) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {The plane turns to face us.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 16.18s = "true", 16.42s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.30,3.39) -- (0.76,4.11) -- (0.30,0.73) -- (6.84,0.00) -- cycle;
\draw[mid] (1.69,4.01) -- (1.23,0.62);
\draw[mid] (2.63,3.90) -- (2.17,0.52);
\draw[mid] (3.56,3.80) -- (3.10,0.42);
\draw[mid] (4.50,3.70) -- (4.04,0.31);
\draw[mid] (5.43,3.59) -- (4.97,0.21);
\draw[mid] (6.37,3.49) -- (5.91,0.11);
\draw[mid] (6.96,0.85) -- (0.41,1.57);
\draw[mid] (7.07,1.70) -- (0.53,2.42);
\draw[mid] (7.19,2.54) -- (0.64,3.26);
\pf{5.72,3.39}
\pf{3.26,3.36}
\pf{2.94,3.10}
\pf{4.53,2.86}
\pf{2.74,2.85}
\pf{1.41,2.81}
\pf{2.57,2.79}
\draw[->, hot, very thick] (3.80,2.06) -- (3.99,3.42);
\pf{2.74,2.60}
\pf{5.22,2.52}
\pf{1.73,2.46}
\pf{2.42,2.36}
\pf{5.13,2.34}
\pf{5.79,2.17}
\pf{3.86,1.99}
\pf{4.40,1.92}
\pf{3.77,1.89}
\draw[->, hot, very thick] (3.80,2.06) -- (6.49,1.76);
\pf{4.62,1.78}
\pf{3.30,1.76}
\pf{3.94,1.76}
\pf{5.16,1.63}
\pf{2.14,1.51}
\pf{3.35,1.50}
\pf{6.85,1.48}
\pf{3.67,1.37}
\draw[->, black, very thick] (3.80,2.06) -- (3.80,2.36);
\pf{2.42,1.30}
\pf{5.71,1.27}
\pf{3.75,1.27}
\pf{3.66,1.24}
\pf{2.86,1.22}
\pf{4.31,1.20}
\node[fill=white, inner sep=1pt] at (6.79,1.86) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.31,3.42) {$\mathbf v_2$};
\node[fill=white, inner sep=1pt] at (3.50,2.45) {$\mathbf v_3$};
\node[anchor=west] at (-0.1,-1.45) {The plane turns to face us.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 16.42s = "true", 16.66s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.23,3.63) -- (0.66,4.11) -- (0.37,0.49) -- (6.94,0.00) -- cycle;
\draw[mid] (1.60,4.04) -- (1.31,0.42);
\draw[mid] (2.54,3.97) -- (2.25,0.35);
\draw[mid] (3.48,3.90) -- (3.18,0.28);
\draw[mid] (4.42,3.83) -- (4.12,0.21);
\draw[mid] (5.35,3.76) -- (5.06,0.14);
\draw[mid] (6.29,3.70) -- (6.00,0.07);
\draw[mid] (7.01,0.91) -- (0.44,1.39);
\draw[mid] (7.09,1.81) -- (0.51,2.30);
\draw[mid] (7.16,2.72) -- (0.59,3.21);
\pf{5.66,3.56}
\pf{3.20,3.42}
\pf{2.89,3.13}
\pf{4.49,2.95}
\pf{2.70,2.85}
\pf{2.54,2.79}
\pf{1.38,2.76}
\draw[->, hot, very thick] (3.80,2.06) -- (3.92,3.52);
\pf{5.20,2.62}
\pf{2.71,2.59}
\pf{5.12,2.41}
\pf{1.72,2.40}
\pf{2.41,2.32}
\pf{5.78,2.26}
\pf{3.86,1.99}
\pf{4.41,1.94}
\pf{3.78,1.88}
\draw[->, hot, very thick] (3.80,2.06) -- (6.51,1.86);
\pf{4.64,1.79}
\pf{3.96,1.74}
\pf{3.31,1.72}
\pf{5.18,1.66}
\pf{6.87,1.58}
\pf{3.38,1.44}
\pf{2.17,1.40}
\pf{3.71,1.32}
\pf{5.75,1.30}
\pf{3.79,1.21}
\pf{2.46,1.19}
\pf{3.70,1.18}
\pf{4.36,1.17}
\pf{2.90,1.13}
\node[fill=white, inner sep=1pt] at (6.80,1.95) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.24,3.52) {$\mathbf v_2$};
\node[anchor=west] at (-0.1,-1.45) {The plane turns to face us.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 16.66s = "true", 16.9s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.17,3.81) -- (0.58,4.06) -- (0.43,0.31) -- (7.02,0.06) -- cycle;
\draw[mid] (1.52,4.02) -- (1.38,0.27);
\draw[mid] (2.46,3.99) -- (2.32,0.23);
\draw[mid] (3.40,3.95) -- (3.26,0.20);
\draw[mid] (4.34,3.91) -- (4.20,0.16);
\draw[mid] (5.28,3.88) -- (5.14,0.13);
\draw[mid] (6.22,3.84) -- (6.08,0.09);
\draw[mid] (7.06,0.99) -- (0.47,1.24);
\draw[mid] (7.09,1.93) -- (0.51,2.18);
\draw[mid] (7.13,2.87) -- (0.54,3.12);
\pf{5.59,3.68}
\pf{3.14,3.44}
\pf{2.85,3.13}
\pf{4.46,3.00}
\pf{2.67,2.84}
\pf{2.51,2.76}
\pf{1.35,2.69}
\pf{5.17,2.69}
\pf{2.69,2.57}
\pf{5.10,2.48}
\draw[->, hot, very thick] (3.80,2.06) -- (3.86,3.57);
\pf{5.77,2.35}
\pf{1.70,2.33}
\pf{2.40,2.27}
\pf{3.87,1.99}
\pf{4.41,1.96}
\pf{3.78,1.87}
\pf{4.65,1.82}
\pf{3.97,1.74}
\pf{5.19,1.70}
\pf{3.33,1.69}
\pf{6.89,1.68}
\draw[->, hot, very thick] (3.80,2.06) -- (6.51,1.95);
\pf{3.40,1.41}
\pf{5.78,1.36}
\pf{2.20,1.32}
\pf{3.74,1.29}
\pf{3.82,1.19}
\pf{4.39,1.16}
\pf{3.74,1.15}
\pf{2.50,1.11}
\pf{2.94,1.06}
\node[fill=white, inner sep=1pt] at (6.81,2.05) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.18,3.57) {$\mathbf v_2$};
\node[anchor=west] at (-0.1,-1.45) {The plane turns to face us.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 16.9s = "true", 17.14s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.12,3.92) -- (0.52,3.99) -- (0.48,0.20) -- (7.08,0.13) -- cycle;
\draw[mid] (1.47,3.98) -- (1.43,0.19);
\draw[mid] (2.41,3.97) -- (2.37,0.18);
\draw[mid] (3.35,3.96) -- (3.31,0.17);
\draw[mid] (4.29,3.95) -- (4.25,0.16);
\draw[mid] (5.23,3.94) -- (5.19,0.15);
\draw[mid] (6.17,3.93) -- (6.13,0.14);
\draw[mid] (7.09,1.08) -- (0.49,1.14);
\draw[mid] (7.10,2.02) -- (0.50,2.09);
\draw[mid] (7.11,2.97) -- (0.51,3.04);
\pf{5.55,3.74}
\pf{3.10,3.44}
\pf{2.82,3.11}
\pf{4.43,3.03}
\pf{2.65,2.81}
\pf{2.49,2.73}
\pf{5.15,2.73}
\pf{1.34,2.63}
\pf{2.67,2.54}
\pf{5.09,2.52}
\pf{5.76,2.40}
\pf{1.70,2.28}
\pf{2.39,2.24}
\pf{3.87,1.99}
\pf{4.41,1.97}
\pf{3.79,1.87}
\pf{4.65,1.84}
\pf{6.90,1.76}
\pf{3.98,1.74}
\pf{5.20,1.74}
\pf{3.34,1.68}
\draw[->, hot, very thick] (3.80,2.06) -- (3.82,3.59);
\pf{5.80,1.40}
\pf{3.42,1.39}
\pf{3.76,1.28}
\pf{2.22,1.27}
\pf{3.85,1.18}
\pf{4.42,1.17}
\pf{3.76,1.14}
\pf{2.52,1.07}
\pf{2.97,1.03}
\draw[->, hot, very thick] (3.80,2.06) -- (6.51,2.03);
\node[fill=white, inner sep=1pt] at (6.81,2.13) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.14,3.59) {$\mathbf v_2$};
\node[anchor=west] at (-0.1,-1.45) {The plane turns to face us.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 17.14s = "true", 20.54s = "false", 20.54s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (7.10,3.95) -- (0.50,3.95) -- (0.50,0.16) -- (7.10,0.16) -- cycle;
\draw[mid] (1.45,3.95) -- (1.45,0.16);
\draw[mid] (2.39,3.95) -- (2.39,0.16);
\draw[mid] (3.33,3.95) -- (3.33,0.16);
\draw[mid] (4.27,3.95) -- (4.27,0.16);
\draw[mid] (5.21,3.95) -- (5.21,0.16);
\draw[mid] (6.15,3.95) -- (6.15,0.16);
\draw[mid] (7.10,1.11) -- (0.50,1.11);
\draw[mid] (7.10,2.06) -- (0.50,2.06);
\draw[mid] (7.10,3.00) -- (0.50,3.00);
\pf{5.53,3.76}
\pf{3.09,3.43}
\pf{2.81,3.10}
\pf{4.42,3.04}
\pf{2.64,2.80}
\pf{5.15,2.75}
\pf{2.48,2.72}
\pf{1.33,2.60}
\pf{2.67,2.53}
\pf{5.09,2.53}
\pf{5.76,2.42}
\pf{1.69,2.25}
\pf{2.39,2.22}
\pf{3.87,1.99}
\pf{4.41,1.98}
\pf{3.79,1.87}
\pf{4.66,1.85}
\pf{6.90,1.80}
\pf{5.21,1.75}
\pf{3.98,1.74}
\pf{3.34,1.67}
\pf{5.80,1.42}
\pf{3.43,1.39}
\pf{3.77,1.28}
\pf{2.23,1.25}
\pf{3.86,1.18}
\pf{4.43,1.17}
\pf{3.77,1.14}
\pf{2.53,1.05}
\pf{2.98,1.02}
\draw[->, hot, very thick] (3.80,2.06) -- (3.80,3.59);
\draw[->, hot, very thick] (3.80,2.06) -- (6.51,2.06);
\node[fill=white, inner sep=1pt] at (6.81,2.15) {$\mathbf v_1$};
\node[fill=white, inner sep=1pt] at (4.12,3.59) {$\mathbf v_2$};
\node[anchor=west] at (-0.1,-1.45) {Facing the plane, each point's coordinates along $\mathbf v_1, \mathbf v_2$ are its 2D scores $\mathbf X\mathbf V_2$.};
\end{scope}
\end{tikzpicture}
\end{document}

Properties

(Centering Matters) Without centering, the first direction points toward the mean instead of along the spread.

An uncentered SVD finds the best subspace through the origin. When the data sit far from the origin, the best single direction points at the cloud, close to . Its squared singular value is then close to , which measures the distance of the cloud from the origin. In the Hard example below, a direction away from the main axis of spread reports a share of . Centering also lowers the rank. The rows of a centered matrix sum to zero, so its rank is at most .

(Scale Dependence) Changing the units of one feature changes the principal directions.

A feature measured in grams has times the variance of the same feature in kilograms. That feature then dominates , and points almost along its axis. Standardizing each feature to unit variance gives the PCA of the correlation matrix. With two standardized features of correlation , the directions are always and . The first of them explains of the variance. Standardizing is the wrong choice when all features share a unit and their variances carry meaning. Image pixels are an example. It would inflate pixels that barely vary, such as a plain background.

(Uncorrelated Scores) The scores along different principal directions are uncorrelated, and their variances are the .

The sample covariance of the scores is

because the columns of are orthonormal. With , PCA rotates the axes, possibly with a reflection, so that the covariance becomes diagonal. Dividing each score by gives whitened data with identity covariance. Uncorrelated scores are guaranteed to be independent only when the data are jointly Gaussian.

(Compute With the SVD) Forming squares the condition number, so computing the SVD of directly is more accurate.

The eigenvalues of are the squares . A ratio becomes , beyond the relative precision of double-precision numbers. The small components are then lost to rounding. A full SVD of costs . Randomized SVD (Halko, Martinsson and Tropp 2011) finds the top components in about . When , as with images or gene data, the matrix is smaller. Its eigenvectors are the , and .

(Variance Is Not Relevance) PCA ignores labels, so it can drop the direction that matters for prediction.

PCA ranks directions by spread alone. Take two classes that form thin parallel clouds and differ only across their short side. The first principal direction runs along the clouds and mixes the classes. The dropped direction is the one that separates them. Linear discriminant analysis in 4.2. Linear Discriminants uses the labels and finds it. Principal component regression, which regresses the target on the top components, has the same risk. PCA is also linear, so it cannot flatten data that lie near a curved surface. A nonlinear autoencoder can.

Derivation

We derive the maximum-variance view and show that it agrees with the minimum-error view. Project the centered samples onto a unit vector . The projections have mean zero, so their sample variance is

We maximize this subject to . The Lagrangian has gradient . Setting it to zero gives the eigenvalue equation . At such a the variance is , so the best choice is the eigenvector of the largest eigenvalue. Repeating the argument among vectors orthogonal to gives the second eigenvector, and so on.

The SVD connects these eigenvectors to . Substituting and using gives

an eigendecomposition with eigenvectors and eigenvalues . The total variance is , which justifies the variance-explained ratio.

For the error view, let have orthonormal columns. Each sample splits into its projection and a perpendicular residual. Pythagoras then gives

where is the Frobenius norm. The left side does not depend on . Maximizing the kept variance is therefore the same as minimizing the error. The choice keeps and leaves the error . By Eckart-Young, no matrix of rank comes closer to , so solves both problems.

Examples

(Easy) Two Judges, Four Divers

Two judges score four divers. Judge A gives , , and . Judge B gives , , and . Each row of the data matrix holds one diver’s two scores.

(Medium) Square Meters Versus Bedrooms

Five houses have floor areas of , , , and m². They have , , , and bedrooms.

(Medium) Compressing a Sensor Log

A factory logs readings from sensors. After centering, the singular values of the data matrix are , , , , and .

(Hard) Forgetting to Center

An analyst runs the SVD on the divers’ raw scores from the Easy example, without subtracting the means.

See Also