[SciPy-User] Weighted kernel density estimate?
Zachary Pincus
zachary.pincus at yale.edu
Mon May 27 10:33:28 EDT 2013
> I have a probability distribution represented as a set of weighted
> samples. I'd like to visualize it. Right now I'm using the weights=
> argument to np.histogram2d to do this, which is nice. What would be
> even nicer, though, would be if I could use a KDE instead of
> histogram. But the Python KDE routines I've found in a quick google
> (like, scipy.stats.kde) don't seem to have any sort of weights
> argument. Any suggestions?
>
There have been a couple threads on this topic:
http://mail.scipy.org/pipermail/scipy-user/2012-May/032202.html
http://mail.scipy.org/pipermail/scipy-user/2013-January/033956.html
Attached is a modification to the scipy KDE routine that handles weights (only for density estimation, and none of the other tasks like integration), based on these threads.
The code is not well tested, but seems to work. See the previous threads for some caveats...
Zach
-------------- next part --------------
A non-text attachment was scrubbed...
Name: weighted_kde.py
Type: text/x-python-script
Size: 4770 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20130527/503f77dd/attachment.bin>
More information about the SciPy-User
mailing list