Skip to main content

KernSmooth for Python

Porting popular R library KernSmooth to python.

Functions for Kernel Smoothing and Density Estimation.

Transformed R and Fortran functions into Python(2,3) code.

Attention:

Please use kern-smooth 1.1.0 or newer. Reason: found not needed log10 density transformation.

Installation:

pip install kern-smooth

Main function of the module:

def densCols(x, y=None, nbin=128, bandwidth=None)

Produces a vector of numbers which encode the local densities at each point in dataset.

x, y : 1D numpy array with coordinates of the points density will be estimated on

nbin[optional] int or [int, int] - number of bins along each axis

(in case of single value - [nbin, nbin] will be used). Default value 128.

bandwidth : [optional] numeric vector (len of 1 or 2) of smoothing bandwidth.

Returns: numpy array with numerical representation (in range [0,1]) of point densities.

Attention: For return value numpy.nan values are allowed in case of nan / infinite values in original dataset

Source: R::grDevices::densCols

Usage

Generate data for plotting (make sure Matplotlib is installed)

from matplotlib import pyplot as plt
from matplotlib import cm
import numpy as np
np.random.seed(0)
# create two 'bulbs' with normal distributions
mean1 = [0, 0]
cov1 = [[5, 0], [0, 30]]  # diagonal covariance
x1, y1 = np.random.multivariate_normal(mean1, cov1, 50000).T
mean2 = [5, 17]
cov2 = [[30, 0], [0, 5]]  # diagonal covariance
x2, y2 = np.random.multivariate_normal(mean2, cov2, 50000).T
x = np.hstack([x1,x2])
y = np.hstack([y1,y2])

Generate point densities:

from kern_smooth import densCols
densities = densCols(x, y, nbin = 128)

Plot the result

sc = plt.scatter(x, y, c=densities, s=15, edgecolors='none', alpha=0.75, cmap=cm.jet)
plt.colorbar(sc)
plt.show()

Result

![Result](https://github.com/AlexanderButyaev/kern_smooth/blob/master/example_density.png)

Author

Alexander Butyaev

Metadata

Release files for kern-smooth 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kern-smooth 1.2.3
File Size Uploaded Provenance Actions
kern-smooth-1.2.3.tar.gz 295.6 kB Without provenance Details for kern-smooth-1.2.3.tar.gz

Release files / kern-smooth-1.2.3.tar.gz

Download URL kern-smooth-1.2.3.tar.gz
Size 295.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f8eed9ee2a26352593fea4814bc9509dced9e9c26c049cfce190d5c1a0a16c2c
BLAKE2b-256 checksum
How to use checksums
bcd0d61b3eae81a033a4c1a37537fcac2419afd59549ee7deabc147cf5351a31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Security for kern-smooth 1.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page