Probability calculation with Naive Bayes Probability Density Function by hand
1 次查看(过去 30 天)
显示 更早的评论
veri = readtable ('gh.csv');
vericell = table2cell(veri);
ghcolumn = cell2mat(vericell(:,3));
veri.Class = discretize(veri{:, 3}, min(veri{:, 3}):29:max(veri{:, 3})+29); %with this column I am seperating my dataset into classes with intervals according to 3rd column of my dataset.
vericell = table2cell(veri);
class = cell2mat(vericell(:,end));
for ii=min(veri.Class):max(veri.Class)
deneme{ii,:}=vericell (class==ii,:);
deneme{ii,:}=cell2table(deneme{ii});
end
vericell = cell2table(vericell);
predictioncolumn = readtable("predictioncolumn.csv");
predictioncolumn = table2array(predictioncolumn);
for ii=min(veri.Class):max(veri.Class)
deneme{ii,:}= vericell(class==ii,:);
for j = 4:14
deneme{ii}{:,j};
end
for kk = min(veri.Class):max(veri.Class)
for s = 4:14
meanres(kk,s) = mean (deneme{kk}{:,s});
stdres(kk,s) = std(deneme{kk}{:,s});
end
end
for bb = min(veri.Class):max(veri.Class)
for q = 4:14
uscalc(bb,q) = (predictioncolumn(q) - meanres(bb,q)) ^2 / (2* (stdres(bb,q)^2));
end
end
for mm = min(veri.Class):max(veri.Class)
for d = 4:14
meancalc(mm,d) = 1/(sqrt(2*pi)* stdres(mm,d)) * (2.71^(uscalc(mm,d)));
bolumler{mm,:} = sum(veri.Class==mm)/ length(veri.Class);
end
end
classcarpimlari = meancalc(:,4:14);
multiplycolumns = prod(classcarpimlari,2); end
for nn = min(veri.Class):max(veri.Class);
likelihood(nn) = multiplycolumns(nn) * bolumler{nn};
end
for gg = min(veri.Class):max(veri.Class);
probability(gg) = likelihood(gg) / sum(likelihood);
end
I am trying to apply Naive Bayes Probability Density Function on my data set for my graduation project. And my advisor wanted me to do it by hand. If I set my intervals as 29 at the forth row of my code, it works and calculate the probability of my values belonging to any class. But if I change that as 28 or lower than that, it can not calculate it. Why is that?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!