[SciPy-user] scipy.stats.gaussian_kde broken?

Zachary Pincus zpincus at stanford.edu
Tue Mar 28 19:33:21 EST 2006


Hi folks,

I can't seem to get scipy.stats.gaussian_kde to work properly. Here  
is an example.

[In:] scipy.__version__
'0.4.9.1754'
[In: ] numpy.__version__
'0.9.7.2262'
[In:] k = scipy.stats.gaussian_kde([-2, -1, -0.5, 0, 0, 0, 0, 0.5, 1,  
2])
[In:] k([-100, -2, 0, 2, 100])
array([ 0.52684053,  0.58537837,  0.52762998,  0.52684053,  0.52684053])

Clearly the above result is wrong. The 'dataset' points cluster  
around zero, and have no support anywhere near 100 or -100. Yet the  
estimated density is essentially flat across that whole range.

Even more strange is the fact that when the size of the set of points  
to estimate the density at is larger than the size of the data, the  
first estimated value is different than the others.
[In:] k([-2])
array([ 0.58537837])
[In:] k([-2] * 7)
array([ 0.58537837,  0.58537837,  0.58537837,  0.58537837,  0.58537837,
         0.58537837,  0.58537837])
[In:] k([-2] * 10)
array([ 0.08691171,  0.58537837,  0.58537837,  0.58537837,  0.58537837,
         0.58537837,  0.58537837,  0.58537837,  0.58537837,   
0.58537837])

In fact, I suspect that this first estimated value is the correct  
value, and the rest are garbage.

Any thoughts?

Zach Pincus
Program in Biomedical Informatics and Department of Biochemistry
Stanford University School of Medicine




More information about the SciPy-User mailing list