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
Hi Rui_Kang
You have to calculate the covariance matrix for X_demeaned.
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:
> 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?
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?