[SciPy-user] KDE question

David Cournapeau david at ar.media.kyoto-u.ac.jp
Sat Nov 10 06:13:31 EST 2007


Gael Varoquaux wrote:
> On Fri, Nov 09, 2007 at 02:34:11PM -0500, Zachary Pincus wrote:
>> I'm using scipy.stats.gaussian_kde to estimate the a probability  
>> density based on some scattered 2D samples. What I would like to do  
>> eventually is plot a line that surrounds (say) 90% of the probability  
>> density.
>
> If its only plotting you are interested in, matplotlib can do all the
> dirty work for you, using the "contour" command:
>
> http://matplotlib.sourceforge.net/screenshots/pcolor_demo.py
> which yields:
> http://matplotlib.sourceforge.net/screenshots/pcolor_demo_large.png
I missed this was for plotting. Then the code from the EM toolbox may 
actually be useful, since I used the function mentioned before to plot 
density contours for mixture of Gaussians:

http://www.ar.media.kyoto-u.ac.jp/members/david/softwares/em/pdfestimation.png

Code there: 
http://projects.scipy.org/scipy/scikits/browser/trunk/learn/scikits/learn/machine/em/gauss_mix.py 
(function density_on_grid: this can be used from a Gaussian mixture 
class, that you may be able use easily from gauss_kde). This may not be 
adapted for your case, since I only coded it with a few Gaussians in 
mind (e.g. I have never tried to do something smart, since I don't need 
mixtures of say 500 Gaussian).

cheers,

David



More information about the SciPy-User mailing list