Felix
Felix

Reputation: 3591

A simple fixed-bandwidth 1D Gaussian KDE implementation for Python

I need a simple Kernel Density Estimation with fixed bandwidth and Gaussian kernel.

Alas, in scipy.stats.gaussian_kde I saw only an automatic bandwidth selection. The set_bandwidth method, as far as I see, only multiplies the auto-selected values with some correcting ratios. And I just need to set the bandwidth I want to set.

I don't want to use my hand-written Python code for KDE: it works a bit too slow.

Don't you know any replacements of scipy.stats.gaussian_kde?

Upvotes: 1

Views: 3178

Answers (4)

Michael Baudin
Michael Baudin

Reputation: 1151

You might use the KernelSmoothing class in OpenTURNS. An example is provided in Non parametric distribution fitting and the theory is described here. There is an automatic multidimensional bandwidth rule, but the bandwidth can be set by the user. Also, the library provides the Sheather and Jones "solve-the-equation" plugin rule which is efficient for multimodal distributions and a mixed rule (which is less CPU consuming than the former).

Upvotes: 0

sdenton4
sdenton4

Reputation: 219

You can also try the KDE's in scikit-learn (sklearn): http://scikit-learn.org/stable/modules/density.html It has a variety of different kernels you can try, and lets you directly set bandwidth, but apparently (!) has no methods for automatic bandwidth selection.

Upvotes: 1

jseabold
jseabold

Reputation: 8283

You might be interested in KDE in statsmodels. Example here.

Upvotes: 1

Bitwise
Bitwise

Reputation: 7805

In scipy.stats.gaussian_kde, you can supply a scalar to the bw_method option. This will set the kde.factor variable. kde.factor is a number by which the covariance matrix is multiplied, so it should be the same as the bandwidth.

Upvotes: 1

Related Questions