I'm trying to perform a Kernel Density Estimation on my histogram which has been computed over an image:
I use scikit learn to compute the kernel density estimation using a gaussian kernel:
histogram = np.histogram(img, bins=256, range=(0,255), normed=False)
X = histogram[0][:, np.newaxis]
X_plot = np.linspace(0,255,256,)[:, np.newaxis]
kde = KernelDensity(kernel='gaussian', bandwidth=0.5).fit(X)
log_dens = kde.score_samples(X_plot)
res = np.exp(log_dens)
However, when I plot 'res', I only get its first 3/4 values which differ from 0. I do not understand why I do not get a good estimate while I have followed the instructions given here:
http://scikit-learn.org/stable/auto_examples/neighbors/plot_kde_1d.html