KDEpy
raw JSON → 1.1.12 verified Fri May 01 auth: no python
KDEpy is a Python library for kernel density estimation (KDE). It provides implementations of various KDE methods including naive, convolution, FFT, and tree-based approaches. Current version is 1.1.12. Release cadence is irregular, with updates primarily for compatibility and bug fixes.
pip install kdepy Common errors
error ModuleNotFoundError: No module named 'kdepy' ↓
cause Incorrect import casing. The correct package name is 'KDEpy' with uppercase K, D, E.
fix
Install with
pip install kdepy (lowercase) but import as from KDEpy import .... error AttributeError: module 'KDEpy' has no attribute 'KDE' ↓
cause Attempting to access a class that doesn't exist. KDEpy's main class is `FFTKDE`, not `KDE`.
fix
Use
from KDEpy import FFTKDE instead of from KDEpy import KDE. error ValueError: The bandwidth parameter must be a positive float, a string, or a callable. ↓
cause Passing an invalid value for `bw`. Common mistake: passing an integer or negative number.
fix
Ensure
bw is a positive float, one of the supported string methods ('silverman', 'SCOTT', 'ISJ'), or a callable. error TypeError: fit() got multiple values for argument 'data' ↓
cause Calling `fit` with positional argument after keyword argument, e.g., `kde.fit(bw='ISJ', data)`. Fit expects first positional argument as data.
fix
Use
kde.fit(data, bw='ISJ') or kde.fit(data) after setting bw earlier. error ImportError: cannot import name 'KDE' from 'KDEpy' (unknown location) ↓
cause Old API. In earlier versions (<1.0) the main class was named `KDE`. It was renamed to `FFTKDE` in v1.0.
fix
Upgrade to latest version and use
FFTKDE. If stuck on old version, import KDE. Warnings
gotcha The import path uses mixed case: `from KDEpy import ...`. Lowercase `from kdepy import ...` will fail. ↓
fix Use uppercase KDE in the import statement.
gotcha The Bandwidth class is not exposed in the top-level namespace. Users may mistakenly attempt to import it directly from KDEpy. ↓
fix Use `from KDEpy.bandwidth import Bandwidth` or rely on automatic bandwidth selection via `bw` parameter.
gotcha In KDEpy, the default bandwidth selection method changed between versions. In v1.1.0+, the default for FFTKDE is 'ISJ' (Improved Sheather-Jones) instead of 'silverman'. ↓
fix Explicitly specify `bw='silverman'` if you need the old default.
deprecated The `bw_method` keyword argument was deprecated in v1.0.0 in favor of `bw`. ↓
fix Use `bw` instead of `bw_method`.
Imports
- KDE wrong
from kdepy import KDEcorrectfrom KDEpy import KDE - FFTKDE
from KDEpy import FFTKDE - NaiveKDE
from KDEpy import NaiveKDE - TreeKDE
from KDEpy import TreeKDE
Quickstart
import numpy as np
from KDEpy import FFTKDE
# Generate sample data
np.random.seed(123)
data = np.random.normal(0, 1, size=100)
# Fit KDE
kde = FFTKDE(bw='ISJ')
x, y = kde.fit(data).evaluate(1024)
# Plot
import matplotlib.pyplot as plt
plt.plot(x, y)
plt.show()