Why I get two different covariance matrix?
Show older comments
Hi all,
Prof. Andrew Ng in his ML class says that we can calculate covariance matrix as: 1/m*X'*X .
Where;
examples are in rows of X,
X' is transpose of X,
and, m is number of examples.
For example:
X=randi(12,[6,2]);
cov1=1/size(X,1)*X'*X
And, covariance with cov function is:
cov2=cov(X)
As you can see, cov1 is different from cov2 !!!
What is the reasan for that? Do you have any idea?
Thanks
Accepted Answer
More Answers (1)
4 Comments
John D'Errico
on 14 Jul 2022
Edited: John D'Errico
on 14 Jul 2022
PLEASE DON"T ASK a new question as an answer to your own question! In fact, I won't answer a question posed as you have done, and I could probably do so.
ali yaman
on 14 Jul 2022
John D'Errico
on 14 Jul 2022
Edited: John D'Errico
on 14 Jul 2022
Since this is probably of some general interest, I'll actually post a question of my own, then answer it myself, discussing the relative issues between eig and svd.
ali yaman
on 14 Jul 2022
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!