This documentation is for astroML version 0.2

This page


astroML Mailing List

GitHub Issue Tracker


Scipy 2012 (15 minute talk)

Scipy 2013 (20 minute talk)


If you use the software, please consider citing astroML. astroML.density_estimation.KDE

class astroML.density_estimation.KDE(metric='gaussian', h=None, **kwargs)

Kernel Density Estimate


Deprecated in astroML 0.2 Scikit-learn version 0.14 added a KernelDensity estimator class which has much better performance than this class. The KDE class will be removed in astroML version 0.3.

Parameters :

metric : string or callable

[‘gaussian’|’tophat’|’exponential’] or one of the options in sklearn.metrics.pairwise_kernels. See pairwise_kernels documentation for more information. For ‘gaussian’ or ‘tophat’, ‘exponential’, and ‘quadratic’, the results will be properly normalized in D dimensions. This may not be the case for other metrics.

h : float (optional)

if metric is ‘gaussian’ or ‘tophat’, h gives the width of the kernel. Otherwise, h is not referenced.

**kwargs : :

other keywords will be passed to the sklearn.metrics.pairwise_kernels function.

See also

-, -, -


Kernel forms are as follows:

  • ‘gaussian’ : K(x, y) ~ exp( -0.5 (x - y)^2 / h^2 )

  • ‘tophat’ : K(x, y) ~ 1 if abs(x - y) < h

    ~ 0 otherwise

  • ‘exponential’ : K(x, y) ~ exp(- abs(x - y) / h)

  • ‘quadratic’ : K(x, y) ~ (1 - (x - y)^2) if abs(x) < 1

    ~ 0 otherwise

All are properly normalized, so that their integral over all space is 1.


eval(X) Evaluate the kernel density estimation
fit(X) Train the kernel density estimator
__init__(metric='gaussian', h=None, **kwargs)