Home » , » Kernel Density Estimation with scipy

Kernel Density Estimation with scipy

Kernel Density Estimation with scipy

This post continues the last one where we have seen how to how to fit two types of distribution functions (Normal and Rayleigh). This time we will see how to use Kernel Density Estimation (KDE) to estimate the probability density function. KDE is a nonparametric technique for density estimation in which a known density function (the kernel) is averaged across the observed data points to create a smooth approximation. Also, KDE is a non-parametric density estimators, this means that the estimator has not a fixed functional form but only it depends upon all the data points we used to reach an estimate and the result of the procedure has no meaningful associated parameters. Let's see the snippet:
from scipy.stats.kde import gaussian_kde
from scipy.stats import norm
from numpy import linspace,hstack
from pylab import plot,show,hist

# creating data with two peaks
sampD1 = norm.rvs(loc=-1.0,scale=1,size=300)
sampD2 = norm.rvs(loc=2.0,scale=0.5,size=300)
samp = hstack([sampD1,sampD2])

# obtaining the pdf (my_pdf is a function!)
my_pdf = gaussian_kde(samp)

# plotting the result
x = linspace(-5,5,100)
plot(x,my_pdf(x),'r') # distribution function
hist(samp,normed=1,alpha=.3) # histogram
show()
The result should be as follows:


http://jakevdp.github.io/blog/2013/12/01/kernel-density-estimation/

6 Comments:

sri said...

Thanks for sharing this.,
Leanpitch provides crash course in Brain hacks using NLP everyone can use it wisely.

NLP training

NLP crash course

sri said...

Excellent content ,Thanks for sharing this .,
Leanpitch provides online training in CSPO everyone can use it wisely.,
Join Leanpitch 2 Days CSPO Certification Workshop in different cities.

CSPO certification

CSPO TRAINING

sri said...

Excellent content ,Thanks for sharing this .,
Leanpitch provides online training in CSPO everyone can use it wisely.,
Join Leanpitch 2 Days CSPO Certification Workshop in different cities.

Product owner certification

CSPO certification online

sri said...


Excellent content ,Thanks for sharing this .,
Leanpitch provides online training in CSPO everyone can use it wisely.,
Join Leanpitch 2 Days CSPO Certification Workshop in different cities.
Certified scrum product owner

CSPO online certification

sri said...


Excellent content ,Thanks for sharing this .,
Leanpitch provides online training in CSPO everyone can use it wisely.,
Join Leanpitch 2 Days CSPO Certification Workshop in different cities.
CSPO ONLINE TRAINING

CSPO ONLINE

Anonymous said...

Queen Casino review | 200% up to €300 | CasinoInJapan.com
Queen Casino review. A huge 온카지노 variety of online casinos offer a range of welcome bonus promotions to entice you to join our sister 1xbet korean sites and play games クイーンカジノ

Popular Posts