From ac368dd0c1a913ae43eaf7910113c3d1f3bd0d4e Mon Sep 17 00:00:00 2001 From: mhjensen Date: Thu, 2 Jan 2020 10:45:16 +0100 Subject: [PATCH] more pca --- doc/pub/DimRed/html/._DimRed-bs018.html | 41 +++++++++++------- doc/pub/DimRed/html/DimRed-reveal.html | 40 +++++++++++------- doc/pub/DimRed/html/DimRed-solarized.html | 41 +++++++++++------- doc/pub/DimRed/html/DimRed.html | 41 +++++++++++------- doc/pub/DimRed/ipynb/DimRed.ipynb | 40 +++++++++++------- doc/pub/DimRed/ipynb/ipynb-DimRed-src.tar.gz | Bin 190 -> 191 bytes doc/pub/DimRed/pdf/DimRed-minted.pdf | Bin 263343 -> 263641 bytes doc/src/DimRed/DimRed.do.txt | 42 +++++++++++-------- doc/src/DimRed/Programs/PCAsimple.py | 41 +++++++++--------- 9 files changed, 177 insertions(+), 109 deletions(-) diff --git a/doc/pub/DimRed/html/._DimRed-bs018.html b/doc/pub/DimRed/html/._DimRed-bs018.html index 26757403b..a7cce97b1 100644 --- a/doc/pub/DimRed/html/._DimRed-bs018.html +++ b/doc/pub/DimRed/html/._DimRed-bs018.html @@ -229,7 +229,7 @@ Note that the function multivariate returns also the covariance discussed
import numpy as np
 import pandas as pd
 from IPython.display import display
-n = 100
+n = 10000
 mean = (-1, 2)
 cov = [[4, 2], [2, 2]]
 X = np.random.multivariate_normal(mean, cov, n)
@@ -313,14 +313,15 @@ plt.show()
 

Depending on the number of points \( n \), we will get results that are close to the covariance values defined above. +The plot shows how the data are clustered around a line with slope close to one. Is this expected?

Diagonalize the sample covariance matrix to obtain the principal components

Now we are ready to solve for the principal components! To do so we -diagonalize the sample covariance matrix \( \Sigma_n \). We can use the +diagonalize the sample covariance matrix \( \Sigma \). We can use the function np.linalg.eig to do so. It will return the eigenvalues and -eigenvectors of \( \Sigma_n \). Once we have these we can perform the +eigenvectors of \( \Sigma \). Once we have these we can perform the following tasks: