# What's the purpose of using “algorithm = ball_tree” in sklearn.neighbors.KernelDensity?

In sklearn.neighbors.KernelDensity，there is a parameter "algorithm = ball_tree". What is its specific role in KDE? Why does KDE need ball_tree

see sklearn.neighbors.KernelDensity(): https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KernelDensity.html#sklearn.neighbors.KernelDensity

I think that using ball tree to search for neighbors will only make the algorithm slower, that's because we have to find K neighbors first (the time complexity of balltree is k*log(n) ), and then we use k neighbors for KDE . This will obviously slow down the algorithm. So why don't we give up looking for neighbors and use all the data for KDE

• To find the neighbours faster. – usεr11852 Aug 24 '20 at 11:51
• Why does KDE need to find neighbors? Shouldn't KDE use all the data? – Gid Aug 24 '20 at 11:53
• No, especially for finite support kernels (eg. triangular, Epanechnikov) it makes no sense to use all data. – usεr11852 Aug 24 '20 at 11:57
• So, does KDE only use the data near the estimation point? How much data will be used? Can this function return the data used? Does using nearby data make KDE get density faster? – Gid Aug 24 '20 at 12:01
• Yes, the KDE by definition is giving more weight to data near the estimation and the weight is specific to the kernel choice. – usεr11852 Aug 24 '20 at 12:03