# Question on C1 W3 PCA Algorithm

**URL:** <https://community.deeplearning.ai/t/question-on-c1-w3-pca-algorithm/196495>\
**Category:** NLP with Classification and Vector Spaces\
**Tags:** week-module-3\
**Created:** [August 31, 2022, 5:47pm UTC](https://community.deeplearning.ai/t/question-on-c1-w3-pca-algorithm/196495 "2022-08-31T17:47:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rui\_Kang](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@Rui\_Kang](https://community.deeplearning.ai/u/Rui_Kang)\
**Post date:** [August 31, 2022, 5:47pm UTC](https://community.deeplearning.ai/t/question-on-c1-w3-pca-algorithm/196495/1 "2022-08-31T17:47:02Z")

</div>

I demeaned my data as follows:  
X\_demeaned = X - np.mean(X, axis=0)  
And the covariance matrix is also calculated:  
covariance\_matrix = np.cov(X, rowvar=False)  
I’m sure that the eigenvalue and eigenvectors are computed and sorted correctly. But the final result is wrong. My result is too small compared with the answers. Can someone help to take a look?  
This is the way I calculate the reduced data:  
X\_reduced = X\_demeaned @ eigen\_vecs\_subset

---

<div class="post-metadata">

**Author:** ![reinoudbosch](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@reinoudbosch](https://community.deeplearning.ai/u/reinoudbosch)\
**Post date:** [August 31, 2022, 11:50pm UTC](https://community.deeplearning.ai/t/question-on-c1-w3-pca-algorithm/196495/2 "2022-08-31T23:50:13Z")

</div>

Hi Rui\_Kang

You have to calculate the covariance matrix for X\_demeaned.

---

<div class="post-metadata">

**Author:** ![Rui\_Kang](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@Rui\_Kang](https://community.deeplearning.ai/u/Rui_Kang)\
**Post date:** [September 3, 2022, 9:12pm UTC](https://community.deeplearning.ai/t/question-on-c1-w3-pca-algorithm/196495/4 "2022-09-03T21:12:51Z")

</div>

Hi reinoudbosch,

Thanks for your reply. I tried to calculate the covariance matrix by using X\_demeaned. But it still doesn’t get correct answers. Here is my output of the test case:

```auto
> Your original matrix was (3, 10) and it became:
> [[4.47663383e-17 -2.63751534e-17]
> [1.01669826e-16 -1.74253877e-16]
> [-2.26003941e-17 1.06121591e-16]]

```

Here is my lab id: brcpvmho. Would it be possible for you to check my code?

---

<div class="post-metadata">

**Author:** ![reinoudbosch](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@reinoudbosch](https://community.deeplearning.ai/u/reinoudbosch)\
**Post date:** [September 5, 2022, 8:34pm UTC](https://community.deeplearning.ai/t/question-on-c1-w3-pca-algorithm/196495/5 "2022-09-05T20:34:35Z")

</div>

Hi Rui\_Kang,

Unfortunately I cannot access your notebook through your labID. Could you send me your notebook as an attachment to a direct mail?
