1

I generated a 2D gaussian distribution (uncorrelated datas)

dist2=np.array([np.random.normal(loc=10,scale=3, size=50000),np.random.normal(loc=5,scale=2, size=50000)])

I calculated the covariance matrix divided by bandwidth factor because the covariance attribute is The covariance matrix of dataset, scaled by the calculated bandwidth (kde.factor) (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.gaussian_kde.html)

from scipy.stats import kde
# Use a kernel density estimator to produce local-counts in this space, and grid them to plot.
k = kde.gaussian_kde(dist2)
k.covariance/k.factor

Diagonal elements are not the square of the sigmas as expected.

I think there is something I have not understood on this bandwidth factor.

Any explanation would be appreciated. Thanks for help.

Stef1611
  • 1,978
  • 2
  • 11
  • 30

1 Answers1

1

In scipy.stats.kde.gaussian_kde the covariance factor is implemented so that k.covariance / k.factor**2 is ~ to np.cov(dist2).

Se here for details Getting bandwidth used by SciPy's gaussian_kde function

Max Pierini
  • 2,027
  • 11
  • 17