Skip to main content

Kernel Density Estimation in Python.

Project description

DOI Build Status Documentation Status PyPI version Downloads

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

KDEpy

About

This Python 3.7+ 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 Distribution

KDEpy-1.1.6.tar.gz (139.0 kB view details)

Uploaded Source

Built Distributions

KDEpy-1.1.6-cp311-cp311-win_amd64.whl (213.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

KDEpy-1.1.6-cp311-cp311-win32.whl (204.0 kB view details)

Uploaded CPython 3.11 Windows x86

KDEpy-1.1.6-cp311-cp311-macosx_10_9_x86_64.whl (222.8 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

KDEpy-1.1.6-cp310-cp310-win_amd64.whl (214.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

KDEpy-1.1.6-cp310-cp310-win32.whl (204.7 kB view details)

Uploaded CPython 3.10 Windows x86

KDEpy-1.1.6-cp310-cp310-macosx_10_9_x86_64.whl (223.9 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

KDEpy-1.1.6-cp39-cp39-win_amd64.whl (215.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

KDEpy-1.1.6-cp39-cp39-win32.whl (205.4 kB view details)

Uploaded CPython 3.9 Windows x86

KDEpy-1.1.6-cp39-cp39-macosx_10_9_x86_64.whl (224.0 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

KDEpy-1.1.6-cp38-cp38-win_amd64.whl (215.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

KDEpy-1.1.6-cp38-cp38-win32.whl (205.3 kB view details)

Uploaded CPython 3.8 Windows x86

KDEpy-1.1.6-cp38-cp38-macosx_10_9_x86_64.whl (222.4 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file KDEpy-1.1.6.tar.gz.

File metadata

  • Download URL: KDEpy-1.1.6.tar.gz
  • Upload date:
  • Size: 139.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for KDEpy-1.1.6.tar.gz
Algorithm Hash digest
SHA256 345e2989abdebcff157d7f4a9d0aa27b531426a75b076ed31ed2f929b3eef2ae
MD5 96a17325254ae65c3baaf904e2374a3b
BLAKE2b-256 7028711d139594250c0face0ec8bc5ad66a7ae227cfe390a8da400bc433269f8

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 213.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a7e6f095dc9e8c85a31c8ef79ed79b29d360b8465c6b0654ad6c253175c327fc
MD5 62c9fc8aacd1f514554d5d1b5b508509
BLAKE2b-256 7783c16e13c7bf6eb5de476037908576d2c20cd858dc02a314903040824fc348

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp311-cp311-win32.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp311-cp311-win32.whl
  • Upload date:
  • Size: 204.0 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 a9887a293f323a2f4aca11431f92fd2e70fd34999254e9cd77fde62729e870d4
MD5 e89ce93f1980a7a241d384118160a12b
BLAKE2b-256 6d59446d577b8fd8e371faf6c3078c3d52ca747512aabcc527a4f09f55a642cd

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for KDEpy-1.1.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dee955aadecf79386f91970670f0e73ee2a0af9a1a213777e58240f8fb3fd0e9
MD5 82a204165a9bcf5d6c998247a0666c97
BLAKE2b-256 7b9d402ab470eed756841cdfdd95f50bf1a9d63cc46ef4c24bd2e1c10e961251

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 214.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e950d200d712d14fdf64952d63a0e658d09fe8c3d796ad71a6e02aeac39aaef9
MD5 57c2deedc098be6cb61690f21a62380f
BLAKE2b-256 f7dd3400287f6693fb5ddf0c21099f983beddd424a3ca663c4a742239d66d424

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp310-cp310-win32.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp310-cp310-win32.whl
  • Upload date:
  • Size: 204.7 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 1421b989d2eef3eb90925fab4abe58e2ca83be7901c6dcfaf25bff921f1e2acf
MD5 5b4a61626ddff271c4e7f5e78855fd5d
BLAKE2b-256 d2c12e2117df578def188cd0d8eedff7ff9751a7ad0019f23431f585a5e7afc9

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for KDEpy-1.1.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 aa034a41a01a1c424a1ad877a0c1d14f61c148f17b18850fb4f71e0ab6c2d2f3
MD5 041982e9a4610fc741a23b2aaff65f44
BLAKE2b-256 9d2ebc7ac6fb632e5d1eeaf54a4d8fbd7509370f628da7e76e2564d1e0d7577e

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 215.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5f55f74205c49cd9f0a831b628372abe12248a1a5ce052af6ca1f69d1385840a
MD5 a51a49450d16497c0796dd752335272a
BLAKE2b-256 fdca44c741cb2cc9d161652fc369f8276a2fa9f37fa4106887b6c6bbf01a8ee0

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp39-cp39-win32.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp39-cp39-win32.whl
  • Upload date:
  • Size: 205.4 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 434be6bb4f4a93545ac3ed9688883c06e82e43e29e3ebbd307d91d1d7946ab39
MD5 4b68d3914d4a39f3c6ef36d36c8056d9
BLAKE2b-256 192763583d223b345945f34fb75364bc2b7f272455639341c78cca915dbc947e

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for KDEpy-1.1.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bb283da92372a3373609a77fddd86127ba06533c5c7b9b691c088c06384afb8a
MD5 741f9ad159bba791c43cbadec9ee1ed1
BLAKE2b-256 d2114c8c29e48473aa1393ffae5661aa67112ecdf866d96cd4b0343648faab9a

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 215.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9e9138b0df9778728b0498cb9d97f37fcb4cf872049b5b49f5ee3585ea0a4985
MD5 901c570a7839137ecf7db223bde1cbf1
BLAKE2b-256 0530499598172e91c3567e7fc16525fb634d618afcda1bdbf42b1bff0adcdc5e

See more details on using hashes here.

File details

Details for the file KDEpy-1.1.6-cp38-cp38-win32.whl.

File metadata

  • Download URL: KDEpy-1.1.6-cp38-cp38-win32.whl
  • Upload date:
  • Size: 205.3 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for KDEpy-1.1.6-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 02a46e930bc6dbd5be3ae1393e5c9afc4bf23994d71cf4b44d0744bba4c4a04b
MD5 ea6ee455ee051ff5578723986f0ab389
BLAKE2b-256 e03283012fbf9191edbce59b7ba1cea526d968791c1c151c3fa37ae67c1ccf84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for KDEpy-1.1.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 19cabc23dfa9029c6b211348db2f107c5bde38e742707b316ba7961c503beebf
MD5 2dba902c79d65f3ceefd8ed0bcec5b58
BLAKE2b-256 34719131a59a51ef93a3f2113dfb91c23c922b1bee247edda66a6c3514987be7

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