diff --git a/doc/src/week43/week43.do.txt b/doc/src/week43/week43.do.txt index a164afc60..eecacf57c 100644 --- a/doc/src/week43/week43.do.txt +++ b/doc/src/week43/week43.do.txt @@ -2837,7 +2837,7 @@ x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\ ===== Writing our own PCA code ===== We will use a simple example first with two-dimensional data -drawn from a multivariate normal distribution with the following mean and covariance matrix: +drawn from a multivariate normal distribution with the following mean and covariance matrix (we have fixed these quantities but will play around with them below): !bt \[ \mu = (-1,2) \qquad \Sigma = \begin{bmatrix} 4 & 2 \\ @@ -2846,8 +2846,8 @@ drawn from a multivariate normal distribution with the following mean and covari \] !et Note that the mean refers to each column of data. -We will generate $n = 1000$ points $X = \{ x_1, \ldots, x_N \}$ from -this distribution, and store them in the $1000 \times 2$ matrix $\bm{X}$. +We will generate $n = 10000$ points $X = \{ x_1, \ldots, x_N \}$ from +this distribution, and store them in the $1000 \times 2$ matrix $\bm{X}$. This is our design matrix where we have forced the covariance and mean values to take specific values. The following Python code aids in setting up the data and writing out the design matrix. Note that the function _multivariate_ returns also the covariance discussed above and that it is defined by dividing by $n-1$ instead of $n$. @@ -2880,7 +2880,7 @@ and the mean-centered data $\bar{X} = \{ \bar{x}_1, \ldots, \bar{x}_n \}$ takes !et When you are done with these steps, print out $\mu_n$ to verify it is close to $\mu$ and plot your mean centered data to verify it is -centered at the origin! Compare your code with the functionality from _Scikit-Learn_ discussed above. +centered at the origin! The following code elements perform these operations using _pandas_ or using our own functionality for doing so. The latter, using _numpy_ is rather simple through the _mean()_ function. !bc pycod df = pd.DataFrame(X) @@ -2933,7 +2933,7 @@ plt.show() !ec 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? +The plot shows how the data are clustered around a line with slope close to one. Is this expected? Try to change the covariance and the mean values. For example, try to make the variance of the first element much larger than that of the second diagonal element. Try also to shrink the covariance (the non-diagonal elements) and see how the data points are distributed. === Diagonalize the sample covariance matrix to obtain the principal components ===