Kernel Density Estimation in Python.

## Project description

Want to cite KDEpy in your work? See the bottom right part of this website for citation information.

# KDEpy

This Python 3.8+ 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. The code is stable and in widespread use by practitioners and in other packages.

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 showing an unweighted and weighted kernel density. 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
import matplotlib.pyplot as plt

customer_ages = [40, 56, 20, 35, 27, 24, 29, 37, 39, 46]

# Distribution of customers
x, y = FFTKDE(kernel="gaussian", bw="silverman").fit(customer_ages).evaluate()
plt.plot(x, y)

# Distribution of customer income (weight each customer by their income)
customer_income = [152, 64, 24, 140, 88, 64, 103, 148, 150, 132]

# The bw parameter can be manually set, e.g. bw=5
x, y = FFTKDE(bw="silverman").fit(customer_ages, weights=customer_income).evaluate()
plt.plot(x, y)


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.

## Project details

### Source Distribution

KDEpy-1.1.9.tar.gz (26.3 kB view hashes)

Uploaded Source

### Built Distributions

KDEpy-1.1.9-cp312-cp312-win_amd64.whl (214.5 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

KDEpy-1.1.9-cp312-cp312-win32.whl (204.2 kB view hashes)

Uploaded CPython 3.12 Windows x86

KDEpy-1.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (558.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

KDEpy-1.1.9-cp312-cp312-macosx_11_0_arm64.whl (216.7 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

KDEpy-1.1.9-cp312-cp312-macosx_10_9_x86_64.whl (223.5 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

KDEpy-1.1.9-cp311-cp311-win_amd64.whl (213.7 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

KDEpy-1.1.9-cp311-cp311-win32.whl (203.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

KDEpy-1.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (571.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

KDEpy-1.1.9-cp311-cp311-macosx_11_0_arm64.whl (216.7 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

KDEpy-1.1.9-cp311-cp311-macosx_10_9_x86_64.whl (223.1 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

KDEpy-1.1.9-cp310-cp310-win_amd64.whl (214.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

KDEpy-1.1.9-cp310-cp310-win32.whl (204.4 kB view hashes)

Uploaded CPython 3.10 Windows x86

KDEpy-1.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (553.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

KDEpy-1.1.9-cp310-cp310-macosx_11_0_arm64.whl (218.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

KDEpy-1.1.9-cp310-cp310-macosx_10_9_x86_64.whl (224.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

KDEpy-1.1.9-cp39-cp39-win_amd64.whl (215.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

KDEpy-1.1.9-cp39-cp39-win32.whl (205.3 kB view hashes)

Uploaded CPython 3.9 Windows x86

KDEpy-1.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (557.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

KDEpy-1.1.9-cp39-cp39-macosx_11_0_arm64.whl (218.3 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

KDEpy-1.1.9-cp39-cp39-macosx_10_9_x86_64.whl (224.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

KDEpy-1.1.9-cp38-cp38-win_amd64.whl (215.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

KDEpy-1.1.9-cp38-cp38-win32.whl (90.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

KDEpy-1.1.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (445.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

KDEpy-1.1.9-cp38-cp38-macosx_11_0_arm64.whl (216.7 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

KDEpy-1.1.9-cp38-cp38-macosx_10_9_x86_64.whl (107.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64