Kernel density estimation Problem graph ?

1 次查看(过去 30 天)
l = linspace(-4,4,500);
fhat = zeros(size(l));
h = 1.06*n^(-1/5);
hold on
for i=1:n % get each kernel function evaluated at x% centered at data
f = exp(-(1/(2*h^2))*(l-x(i)).^2)/sqrt(2*pi)/h;
plot(l,f/(n*h));
fhat = fhat+f/(n);
end
plot(l,fhat);
hold off
Thats my code for kernel density estimation where x(i) is dataset of mixture of gaussian and beta distribution but the graph i am getting is value so small that even i cant see it and i am not sure is it right?

回答(1 个)

Shubh Sahu
Shubh Sahu 2020-5-6
See this piece of code:
f = exp(-(1/(2*h^2))*(l-x(i)).^2)/sqrt(2*pi)/h;
plot(l,f/(n*h));
In this f is a point and l is a vector. So in first place you are plotting point against a vector so it will be very difficult to see. Make fhat an array.
fhat(i)= fhat(i-1)+f/(n);
Note: I will strongly recommend you to see this link. Never plot anything inside for loop until it's very necessary to do that.

类别

Help CenterFile Exchange 中查找有关 Measurements and Feature Extraction 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by