[SciPy-user] stats.gaussian_kde prevent oversmoothing
josef.pktd@gmai...
josef.pktd@gmai...
Sun Jan 4 00:05:25 CST 2009
On Sun, Jan 4, 2009 at 12:05 AM, Robert Kern <robert.kern@gmail.com> wrote:
> On Sat, Jan 3, 2009 at 23:00, <josef.pktd@gmail.com> wrote:
>> I was working on an example for stats.gaussian_kde.
>>
>> In one example I have a 1 dimensional mixture of normal distribution,
>> and the estimated distribution stats.gaussian_kde is too smooth, the
>> peaks are to small compared to the original distribution.
>>
>> What's the easiest way to reduce the bandwidth for stats.gaussian_kde?
>> I didn't find any direct option. Is subclassing the only way?
>
> Currently, yes. Feel free to enhance the code to allow for more flexibility.
>
Thanks,
I tried some quick monkey patching and it works, e.g.
def covariance_factor(self):
return 0.1
gkde=stats.gaussian_kde(xn) #get kde for original sample
setattr(gkde, 'covariance_factor', covariance_factor.__get__(gkde,
type(gkde)))
gkde._compute_covariance()
and then call gkde.evaluate
The automatic covariance_factor was at around 0.25 in the example.
After setting it to 0.1, the kde gets both peaks of the mixture
correctly.
After some googling, I found a discussion from the mailinglist
http://www.nabble.com/Width-of-the-gaussian-in-stats.kde.gaussian_kde---td19558924.html
Currently, I was just trying to find out how the different functions
and classes in scipy.stats work.
Josef
More information about the SciPy-user
mailing list