Python's Sklearn module provides methods to perform Kernel Density Estimation. One of the challenges in Kernel Density Estimation is the correct choice of the kernel-bandwidth.
I have come across the following python-expression to select a bandwidth:
grid = GridSearchCV(KernelDensity(kernel = 'gaussian'),{'bandwidth': np.linspace(0.1, 0.5, 20)}, cv = 5, iid = True)
Here, GridSearchCV
is a method that performs K-Fold Cross-Validation. Here is how I understand it:
We split the data, whose density is to be estimated, into K subsets. We then train the Kernel-Density-Estimation Algorithm with the data points of K-1 subsets. And finally, we evaluate the accuracy of our found parameters on the remaining subset. We repeat the process K times, each time choosing a different subset for testing.
Now, here is my question: In the given python-expression: Which is the algorithm that KernelDensity(kernel = 'gaussian')
makes use of?
Is it a nearest-neighbor algorithm? Does this mean: We consider a data point and place a Gaussian onto it. We will now have a look at all the data points that fall within this Gaussian. From their values, we estimate the value of the data point that we have placed the Gaussian on.
Does anything that I am saying make sense?
KernelDensity()
. But I am also interested in knowing if my understanding ofGridSearchCV
is correct. Do you ask me to alter my question? $\endgroup$kde.py
does not really do any bandwidth estimation; it uses a default value. The "big thing" it does is having an efficient way of finding the neighbours. Given that we have the proximity of the data-points in question we then place the Gaussian (or whatever kernel) on top. $\endgroup$kde
finds its neighbours? $\endgroup$