Skip to main content

Kernel Density Estimation in Python.

Project description

DOI Build Status Build status Documentation Status PyPI version Downloads

KDEpy

About

This Python 3.5+ package implements various kernel density estimators (KDE). Three algorithms are implemented through the same API: NaiveKDE, TreeKDE and FFTKDE. The class FFTKDE outperforms other popular implementations, see the comparison page.

Plot

The code generating the above graph is found in examples.py.

Installation

KDEpy is available through PyPI, and may be installed using pip:

pip install KDEpy

If you have trouble on Ubuntu, try running sudo apt install libpython3.X-dev, where 3.X is your Python version.

Example code and documentation

Below is an example using NumPy as np and scipy.stats.norm to plot a density estimate. From the code below, it should be clear how to set the kernel, bandwidth (variance of the kernel) and weights. See the documentation for more examples.

from KDEpy import FFTKDE
data = norm(loc=0, scale=1).rvs(2**3)
estimator = FFTKDE(kernel='gaussian', bw='silverman')
x, y = estimator.fit(data, weights=None).evaluate()
plt.plot(x, y, label='KDE estimate')

Plot

The package consists of three algorithms. Here's a brief explanation:

  • NaiveKDE - A naive computation. Supports d-dimensional data, variable bandwidth, weighted data and many kernel functions. Very slow on large data sets.
  • TreeKDE - A tree-based computation. Supports the same features as the naive algorithm, but is faster at the expense of small inaccuracy when using a kernel without finite support. Good for evaluation on non-uniform, arbitrary grids.
  • FFTKDE - A very fast convolution-based computation. Supports weighted d-dimensional data and many kernels, but not variable bandwidth. Must be evaluated on an equidistant grid, the finer the grid the higher the accuracy. Data points may not be outside of the grid.

Issues and contributing

Issues

If you are having trouble using the package, please let me know by creating an Issue on GitHub and I'll get back to you.

Contributing

Whatever your mathematical and Python background is, you are very welcome to contribute to KDEpy. To contribute, fork the project, create a branch and submit and Pull Request. Please follow these guidelines:

  • Import as few external dependencies as possible.
  • Use test driven development, have tests and docs for every method.
  • Cite literature and implement recent methods.
  • Unless it's a bottleneck computation, readability trumps speed.
  • Employ object orientation, but resist the temptation to implement many methods -- stick to the basics.
  • Follow PEP8.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

KDEpy-1.0.2.tar.gz (136.7 kB view hashes)

Uploaded Source

Built Distributions

KDEpy-1.0.2-cp38-cp38-manylinux2010_x86_64.whl (419.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

KDEpy-1.0.2-cp38-cp38-manylinux1_x86_64.whl (419.9 kB view hashes)

Uploaded CPython 3.8

KDEpy-1.0.2-cp37-cp37m-win_amd64.whl (110.1 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

KDEpy-1.0.2-cp37-cp37m-win32.whl (97.1 kB view hashes)

Uploaded CPython 3.7m Windows x86

KDEpy-1.0.2-cp37-cp37m-manylinux2010_x86_64.whl (383.6 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

KDEpy-1.0.2-cp37-cp37m-manylinux1_x86_64.whl (383.6 kB view hashes)

Uploaded CPython 3.7m

KDEpy-1.0.2-cp37-cp37m-macosx_10_6_intel.whl (193.3 kB view hashes)

Uploaded CPython 3.7m macOS 10.6+ intel

KDEpy-1.0.2-cp36-cp36m-win_amd64.whl (110.1 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

KDEpy-1.0.2-cp36-cp36m-win32.whl (97.2 kB view hashes)

Uploaded CPython 3.6m Windows x86

KDEpy-1.0.2-cp36-cp36m-manylinux2010_x86_64.whl (384.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

KDEpy-1.0.2-cp36-cp36m-manylinux1_x86_64.whl (384.0 kB view hashes)

Uploaded CPython 3.6m

KDEpy-1.0.2-cp36-cp36m-macosx_10_6_intel.whl (192.9 kB view hashes)

Uploaded CPython 3.6m macOS 10.6+ intel

KDEpy-1.0.2-cp35-cp35m-win_amd64.whl (109.8 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

KDEpy-1.0.2-cp35-cp35m-win32.whl (96.6 kB view hashes)

Uploaded CPython 3.5m Windows x86

KDEpy-1.0.2-cp35-cp35m-manylinux2010_x86_64.whl (379.0 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

KDEpy-1.0.2-cp35-cp35m-manylinux1_x86_64.whl (379.0 kB view hashes)

Uploaded CPython 3.5m

KDEpy-1.0.2-cp35-cp35m-macosx_10_6_intel.whl (190.7 kB view hashes)

Uploaded CPython 3.5m macOS 10.6+ intel

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page