Language: English
Last updated: 2026-04-17
This page: Nonparametric overview
Switch: Chinese
Language switch: Chinese
- Kernel Ridge Regression — KernelRidge, KernelRidgeCV
- Spline Basis Functions — bspline_basis, natural_cubic_spline_basis
- GAM (Semiparametric) — Generalized Additive Model
The nonparametric module provides kernel smoothing methods:
- KDE: density estimation via
fit_kde,kde_pdf, and bootstrap confidence intervals. - Kernel Regression: Nadaraya-Watson (
nw) and local-linear (local_linear) regression via functional APIs and sklearn-style wrappers.
Both families support NumPy/CuPy execution paths and are used in dedicated SciPy/statsmodels/R comparison benchmarks.
KDE:
statgpu.nonparametric.fit_kdestatgpu.nonparametric.kde_pdfstatgpu.nonparametric.kde_bootstrap_confidence_intervalstatgpu.nonparametric.KernelDensityEstimator
Kernel Regression:
statgpu.nonparametric.fit_kernel_regressionstatgpu.nonparametric.kernel_regression_predictstatgpu.nonparametric.KernelRegressionRegressor
- KDE estimates a smooth density (\hat f(x)) from sample points and kernel weights.
- Kernel regression estimates (m(x)=E[Y|X=x]) with kernel-weighted local averaging (
nw) or local linear correction (local_linear).
- KDE: $$ \hat f(x)=\frac{1}{nh}\sum_{i=1}^n K\left(\frac{x-X_i}{h}\right) $$ with selected kernel and bandwidth policy.
- Kernel regression (
nw): $$ \hat m(x)=\frac{\sum_i K_h(x-X_i)Y_i}{\sum_i K_h(x-X_i)} $$ with optional diagonal/full kernel metric behavior.
Nonparametric APIs do not expose a unified cov_type table like parametric models.
- KDE confidence intervals are available through bootstrap (
kde_bootstrap_confidence_interval). - Kernel regression focuses on prediction consistency and cross-framework parity rather than coefficient-level covariance reporting.
Common nonparametric controls:
backend:auto/numpy/cupykernel:gaussian,rectangular,triangular,epanechnikov,biweight,triweight,cosine,optcosinebandwidth:scott,silverman,nrd0,nrd,ucv,bcv,sj,sj-ste,sj-dpi, or numeric- Kernel regression specific:
regression='nw'|'local_linear',kernel_metric='full'|'diagonal',bandwidth_per_feature
import numpy as np
from statgpu.nonparametric import fit_kde, kde_pdf, fit_kernel_regression, kernel_regression_predict
# CPU KDE
x = np.random.randn(500)
grid = np.linspace(-4, 4, 200)
kde = fit_kde(x, bandwidth="scott", kernel="gaussian", backend="numpy")
density = kde_pdf(x, grid, bandwidth="scott", backend="numpy")
# GPU kernel regression
kr = fit_kernel_regression(X_gpu, y_gpu, regression="local_linear", kernel_metric="diagonal", backend="cupy")
y_hat = kernel_regression_predict(X_gpu, y_gpu, Xq_gpu, regression="local_linear", kernel_metric="diagonal", backend="cupy")For kernel regression, kernel_metric="diagonal" is often preferred for strict parity checks against statsmodels diagonal-kernel configurations. Full-kernel settings and broader bandwidth selectors can provide flexibility but may trade exact parity for broader modeling choices.
- KDE: fitted estimator object, density values, and optional bootstrap interval bounds.
- Kernel regression: fitted regressor object and predictions at query points.
- sklearn-style wrappers expose
fit,predict, and scoring-compatible interfaces.
- Which bandwidth rule should I start with?
scottorsilvermanis a reliable baseline; move tosj/CV selectors for harder distributions. - When should I use
local_linearovernw?local_linearusually reduces boundary bias at higher compute cost. - How do I match external frameworks closely? Align kernel type, bandwidth rule/value, and use diagonal metric where required by the comparison target.
- Python benchmarks:
dev/benchmarks/benchmark_kde_vs_scipy.pydev/benchmarks/benchmark_kernel_regression_vs_statsmodels.py
- R benchmark:
dev/benchmarks/benchmark_nonparametric_vs_r.py
- Combined suite:
dev/benchmarks/benchmark_nonparametric_comparison_suite.py
- Representative artifacts:
results/kde_vs_scipy_*.jsonresults/kernel_regression_vs_statsmodels_*.json
- Rosenblatt, M. (1956). Remarks on some nonparametric estimates of a density function. Annals of Mathematical Statistics, 27(3), 832-837. https://doi.org/10.1214/aoms/1177728190
- Parzen, E. (1962). On estimation of a probability density function and mode. Annals of Mathematical Statistics, 33(3), 1065-1076. https://doi.org/10.1214/aoms/1177704472
- Nadaraya, E. A. (1964). On estimating regression. Theory of Probability and Its Applications, 9(1), 141-142. https://doi.org/10.1137/1109020
- Watson, G. S. (1964). Smooth regression analysis. Sankhya: The Indian Journal of Statistics, Series A, 26(4), 359-372.
- Fan, J., & Gijbels, I. (1996). Local Polynomial Modelling and Its Applications. Chapman & Hall.