Kernel density estimation Problem graph ?

1 回表示 (過去 30 日間)
Lakshit Chugh
Lakshit Chugh 2020 年 5 月 3 日
回答済み: Shubh Sahu 2020 年 5 月 6 日
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 Center および File ExchangeMeasurements and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by