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.6+ 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 by practitioners and in other packages.

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 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)

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

KDEpy-1.0.4-cp38-cp38-manylinux2010_x86_64.whl (432.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

KDEpy-1.0.4-cp38-cp38-manylinux1_x86_64.whl (432.3 kB view details)

Uploaded CPython 3.8

KDEpy-1.0.4-cp38-cp38-macosx_10_9_x86_64.whl (116.6 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

KDEpy-1.0.4-cp37-cp37m-manylinux2010_x86_64.whl (396.0 kB view details)

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

KDEpy-1.0.4-cp37-cp37m-manylinux1_x86_64.whl (396.0 kB view details)

Uploaded CPython 3.7m

KDEpy-1.0.4-cp37-cp37m-macosx_10_9_x86_64.whl (115.6 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

KDEpy-1.0.4-cp36-cp36m-manylinux2010_x86_64.whl (396.4 kB view details)

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

KDEpy-1.0.4-cp36-cp36m-manylinux1_x86_64.whl (396.4 kB view details)

Uploaded CPython 3.6m

KDEpy-1.0.4-cp36-cp36m-macosx_10_9_x86_64.whl (115.3 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

Details for the file KDEpy-1.0.4-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 432.3 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for KDEpy-1.0.4-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b453d5e0b98df480dcbf43274449454ff9514649e1e105d1d198ecf7505cd18e
MD5 4709955ebeaaebe9d44c0485acad76f7
BLAKE2b-256 173d04a7699a0c45bf9c06fb7e5a216c1b9a8e9df790a587f7f88679823b8e66

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 432.3 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for KDEpy-1.0.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 30a9e6f1d763e447cfd5c95fa07266ff64d35daddcce802042765154b2686db9
MD5 b84cc0f17953dc6ca3d4ecb5e82e686f
BLAKE2b-256 da0712a9277965b81ca327500a86d6b67bd7518fb2fca4e90d0a06dc024d7570

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 116.6 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for KDEpy-1.0.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b5a39a4e59ee789e278824931af77714e5b882925a13d6835a2a64e5299b7cde
MD5 4b03fc6ba66ae2098f9a72bd1b09f044
BLAKE2b-256 f95d221d120edf5891791bf19df6221027f17bac34c09b4b609234ac5b2abbf7

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 396.0 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for KDEpy-1.0.4-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 d8f893bbc4cda909cfb885b0ddb4c2c9a3043105fdbc9b2fa96c09302d67ae68
MD5 70ba899140c649d8f597538949ec262e
BLAKE2b-256 630ef0c148fcf78afd8af2cf31b88b68edd0938dfab407ee8d85dfe96c594b61

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 396.0 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for KDEpy-1.0.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 81828088a34b23e5563551c4cbc7959824444b962ceb273f2b722a3fa88acedc
MD5 f1db01bc1da7891f5f90adf4680cd36a
BLAKE2b-256 13c01bcc78b8cc986d7c76630f72cc42b885faed71f276598b13076eed89c217

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 115.6 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for KDEpy-1.0.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f378d94650bd6734c4a9b5f4e2320dc336b78f0ffc13693ec766dab0788d7531
MD5 f29b2ae39c2ead6e71794829b3407171
BLAKE2b-256 a82d9b66093d9a6673fa7f64cbedba9c79a1cfa28ea9cff63f1f2fc5ac92860f

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 396.4 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for KDEpy-1.0.4-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f8c16005fc97348f28ee5fd871f500e48b1788c2e1a84c9c8546f95a09765193
MD5 713b490840042246b478b7ccd1e646c8
BLAKE2b-256 f44bbb9cf95e64cbd63a1bd8a40f6b9178b81aaaa0ce70bd72662007c69669fa

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 396.4 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for KDEpy-1.0.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d0a783ad6e7a3ce58d1271fb6b6bcef108b4f8635243e1b4eb0a81dd6ffbfd27
MD5 c9720a48579ef8e76002c7574b9f808d
BLAKE2b-256 1099d4ee11c6b576c57f4b752d8a339f284d74dd7f83a756384f0d7f696eed79

See more details on using hashes here.

File details

Details for the file KDEpy-1.0.4-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: KDEpy-1.0.4-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 115.3 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for KDEpy-1.0.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0649c435da3efb07ab7dbf1f306ebce778d8d0e2f605b3f8bb47346fa982c127
MD5 a3292c47a943e7d9634e380ba9ed0c42
BLAKE2b-256 f7e21a30306c11146b73e2428f20a4171330faf9c28d4a22e9cdcdbc986043bd

See more details on using hashes here.

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