Data visualisation and estimation tools based on kernel regression
Project description
kernelmoments
Estimate and visualize conditional moments — means, variances, covariances, and correlations — using adaptive kernel regression. Built on kernelboost's KernelTree, which partitions data and fits local Nadaraya-Watson estimators with automatic bandwidth selection.
Designed for interactive data exploration. Typically fits in under a second on moderately sized datasets (a few thousand rows on CPU, more with GPU acceleration).
For a full tutorial and examples, see the GitHub repository.
Installation
pip install kernelmoments
For GPU acceleration (CUDA 12):
pip install kernelmoments[gpu]
Quick start
Plot from NumPy arrays with plot_relationship
from kernelmoments import plot_relationship
# Conditional mean with +-1.96*sqrt(Var) prediction bands
result = plot_relationship(x, y, moment="mean", bands=True)
# Conditional variance
result = plot_relationship(x, y, moment="variance")
# Conditional correlation between y and z given x
result = plot_relationship(x, y, z=z, moment="correlation")
Plot from DataFrames with Plotter
from kernelmoments import Plotter
p = Plotter(df, n_sample=5000) # optional subsampling for faster fitting
p.fit(x="age", y="income", z="spending") # pre-fit all moments
p.plot(x="age", y="income") # conditional mean
p.plot(x="age", y="income", moment="variance") # conditional variance
p.plot(x="age", y="income", z="spending", moment="correlation") # conditional correlation
Estimators directly
from kernelmoments import MeanEstimator, VarianceEstimator, CovarianceEstimator
mean_est = MeanEstimator().fit(X, y)
y_hat = mean_est.predict(X_new)
var_est = VarianceEstimator().fit(X, y)
var_hat = var_est.predict(X_new)
cov_est = CovarianceEstimator().fit(X, y, z)
cov_hat = cov_est.predict(X_new)
cov_est.fit_correlation()
corr_hat = cov_est.predict_correlation(X_new)
All estimators follow the scikit-learn fit / predict pattern. Constructor parameters (bandwidth bounds, kernel type, tree depth, etc.) are forwarded to KernelTree.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kernelmoments-0.1.0.tar.gz.
File metadata
- Download URL: kernelmoments-0.1.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5b6c9c14a670be94e0c5f7edba82d6ff2a117fa88ec29fab0dc0dd214c1f5c2
|
|
| MD5 |
8c71e9d9475f039782f587da285bf973
|
|
| BLAKE2b-256 |
2c0e1656bccab709b20e0977eb3abad7f2b94fcc2bd150e2101935a58629572a
|
File details
Details for the file kernelmoments-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kernelmoments-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5a843622dd3aa0fc23d4df3796c998e70ca5231c41aefdba5ae364df222d452
|
|
| MD5 |
faa51651bfd4d849738d9ffb5faba71c
|
|
| BLAKE2b-256 |
d67ab0612326dc49bf3a69d33364f2a89e640df51d87fca15e786f3503366e30
|