Reputation: 861
I am using three functions of python to compute covariance of the same input, the outputs are drastically different. Does anyone have experience and know which one works best? (what are the differences?)
The functions I use are
sklearn.covariance.empirical_covariance(.)
MinCovDet().fit(.)
np.cov(.)
Any insight is appreciated.
The sklearn.covariance.empirical_covariance(.) gives me the straightforward
cov = (1/N) * M.transpose * M
Upvotes: 1
Views: 193
Reputation: 578
Agree with Joseph Hansen, more specificity will be helpful for a thorough answer. Quickly, I believe that sklearn.covariance calculates covariance for the population. Whereas, by default numpy.cov calculates the sample covariance. To obtain the population covariance you can specify normalization by the total N samples like this:
Covariance = numpy.cov(a, b, bias=True)[0][1]
Upvotes: 1