2

When I do kernel density estimation using scipy, it seems that the bandwidth is a fixed value for the whole dataset, although I can set its value by my own.

def scotts_factor(self):
        #Compute Scott's factor.
        return power(self.neff, -1./(self.d+4))

self.covariance_factor = self.scotts_factor
self.factor = self.covariance_factor()   #get the value of bandwidth

By the way, I have checked the code in sklearn to do kernel density estimation, and the code is like belows:

kde = KernelDensity(kernel='gaussian', bandwidth=0.2).fit(X)

Seems for the dataset X, they also shared a common bandwidth.

Therefore, the whole dataset shared a common bandwidth value. And if I want set different bandwidth for every point in a scatterplot, what should I do?

happy
  • 67
  • 7

1 Answers1

0

From what I read it seems that you are not using SciPy at all, but maybe I am wrong.

SciPy offers a class for density estimation, called gaussian_kde. You can read the docs here.

From the docs, the parameter bw_method allows to choose the method to estimate the bandwidth. You can select the already implemented Scott or Silverman methods or you can also provide a callable. You can find other examples here on how to set the bw_method parameter.

blunova
  • 2,122
  • 3
  • 9
  • 21
  • 1
    The code above is the snippet of the Scipy to calculate bandwidth. And I know i can choose a method such as Scott or Silverman to compute the bandwidth. What i mean is in this way, I will use this bandwidth for the whole dataset. But i want to set different bandwidths for every point in the dataset. So in this way, what should i do? – happy Oct 26 '22 at 01:42