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.7.tar.gz (139.0 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 Windows x86

KDEpy-1.1.7-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.7-cp310-cp310-win_amd64.whl (214.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 Windows x86

KDEpy-1.1.7-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.7-cp39-cp39-win_amd64.whl (215.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 Windows x86

KDEpy-1.1.7-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.7-cp38-cp38-win_amd64.whl (215.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.8 Windows x86

KDEpy-1.1.7-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.7.tar.gz.

File metadata

  • Download URL: KDEpy-1.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 a01f8200c98c60e44c2809acdda4bda0bffc01cb0598761def88a66331994d90
MD5 e92266e4a416a11076fc2a07f83db686
BLAKE2b-256 8a9becdf8791e74e890c0306666ee103e8b75262136c956a7bd83ec2307c2f37

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4a8dbb24497fdd06c0760e85105f7a18494169dcf714eb4ed1fd2eeff626a5e5
MD5 8023d50c946bffdb78323d9315296c5e
BLAKE2b-256 0cd519cf51b9e1ed3f59928078cf0974da3883486e787c8b3e07bccd2abf01dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 37fd0a35fae279dab39dc283535a1aaaf2315c0f36edcb46f9330369544a245b
MD5 27b60494b243d22633afcb0b7100186c
BLAKE2b-256 547bd4029897eb1f2cac133388d316074b2bb472a3447dfaed981e840cca4ba8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for KDEpy-1.1.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0f67c768bbc989c72254603ed292173894ad355680a69462590b44f271e75265
MD5 6660fe5edae873994699c3ba421c753c
BLAKE2b-256 b9c0bef6fba35bea326def46e36ebcf8139ee866fca8f9d0f2d4f6adb10601d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c20af67ff450d642ccaa85e326cf2db5d733abade6491c7c5e01fca830bd81f0
MD5 e77a5c1314e4f530d9797eb5c5f6f046
BLAKE2b-256 333551879fb3ccda5b2588faacbb6df96afd66e1668844515b51ff2bce87939c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 cfebcf42c906d7822e8d0e8fb3d346055b69f4d7b215bf3fccc639d95bf81a9e
MD5 ccf3e6f1a4cf88975629bd0ef07bb44c
BLAKE2b-256 e7057c56fc6d26e1ea57f9f1e2458f104ae3779e948e77e801989e0bf3202d9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for KDEpy-1.1.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 989358c0192fb3d05d8c68b544b1f3e5d97d89b8679595818dbad5789d8b92b0
MD5 7ebfa933d6c9e36afd29dacf5234a782
BLAKE2b-256 b73f50240b007a63b3d61dd3729639523a1b49bf02a84bada13048d9da2bddd0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1e9aba128c3562cc2286682cf1a94db4b0a210d4db5ade92e27bf8bb3c88c205
MD5 4b9106f7bae2746688d8efc72ccc2eab
BLAKE2b-256 c902a5964fb3bb14fb4a5b854e0817acd81018dfc5f200db3eb32d871fee1b71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 bfabbf263b5b5a0f9dfdc207b8c901ceb40e0f70e97ce72ec0bb7c699ac7e2d5
MD5 784626b9f435c40289fd448e168ff681
BLAKE2b-256 b1415799f3078664732648920570fe0bd8472fe224611d111d85e3f9119742b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for KDEpy-1.1.7-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ff8b3a8434de40262a34f354b50f0e0d4114f2161d3170b493fb7aad4015796f
MD5 2110eea52dc9774a8ca91456c22d7e11
BLAKE2b-256 b1acffe31629614b101fdc97e0a6394213225cea7523084e49f9fa0026e02858

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 24645d1a61e2bd79b37bf8dfb28fe76c273d6737162a6847be98ff08f8531b2b
MD5 180e8fd2a1dbade97784a22895502d17
BLAKE2b-256 11108d467a0f183a7e728abb289862f49376871001e2466d632b9fc03fa72ef5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KDEpy-1.1.7-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.7-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 eaf358b0c4ade1079c57a0377ec0410260e86755546f7721b1f09493c8a6e0fe
MD5 f6a75548a46ef11d5643375efb34dfb5
BLAKE2b-256 30e210d49d02bc7063f7716888b7f3d77062640b4a2ac5f1d2be8f5fec3f533c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for KDEpy-1.1.7-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0f7942a62fe59f0eb7d2a8d592e4f00a923b4c9925814f379751cc8f9715b5e6
MD5 f1d55e7fa4523c16b7d1757ab38d6a9b
BLAKE2b-256 426c747fc5154fbcacb5f34e5584a08c49abb431f5184d2830507e9588c72b5c

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