title: Kernel density estimation of the histogram of an image
body: <p>I'm trying to perform a Kernel Density Estimation on my histogram which has been computed over an image:</p>
  
  <p>I use scikit learn to compute the kernel density estimation using a gaussian kernel:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>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:</p>
  
  <p><a href="http://scikit-learn.org/stable/auto_examples/neighbors/plot_kde_1d.html" rel="nofollow">http://scikit-learn.org/stable/auto_examples/neighbors/plot_kde_1d.html</a></p>