フィルターのクリア

.mu and .su

5 ビュー (過去 30 日間)
Jon Camilleri
Jon Camilleri 2015 年 11 月 23 日
コメント済み: Walter Roberson 2015 年 11 月 23 日
What do lines 41-42 mean?
% ICS5110 - Applied Machine Learning
% University of Malta
% Lecturer: Dr. George Azzopardi
% Date: 27 October, 2015
function accuracy = NaiveBayesIris(L2norm)
load('irisData.mat');
load('irisLabels.mat');
% Create a random permutation
if exist('randpermlist.mat')
load('randpermlist.mat');
else
randpermlist = randperm(numel(irisLabels));
save randpermlist randpermlist;
end
if L2norm
irisData = normr(irisData);
end
% Split data set into 50% training and 50% testing
ntraining = floor(0.5*numel(irisLabels));
trainingData = irisData(randpermlist(1:ntraining),:);
trainingLabels = irisLabels(randpermlist(1:ntraining));
testingData = irisData(randpermlist(ntraining+1:end),:);
testingLabels = irisLabels(randpermlist(ntraining+1:end));
% Prior class probabilities
uniqueClasses = unique(trainingLabels);
[classidx,classlbl] = grp2idx(trainingLabels);
h = hist(classidx,numel(uniqueClasses));
prior = h./sum(h);
% Likelihood
likelihood.mu = zeros(numel(uniqueClasses),size(trainingData,2)); _/% explanation required_
likelihood.su = zeros(numel(uniqueClasses),size(trthainingData,2)); /% explanation required
for i = 1:numel(uniqueClasses)
idx = find(classidx == i);
likelihood.mu(i,:) = mean(trainingData(idx,:));
likelihood.su(i,:) = std(trainingData(idx,:));
end
% Classification
for i = 1:size(testingData,1)
for j = 1:numel(uniqueClasses)
% Guassian Function Kernel
squaredDifference = (testingData(i,:) - likelihood.mu(j,:)).^2;
normFactor = 1./(sqrt(2*pi)*likelihood.su(j,:));
likelihood.prob = normFactor .* exp(-squaredDifference/(2.*(likelihood.su(j,:).^2)));
%posterior(j) = prod(likelihood.prob) * prior(j);
posterior(j) = sum(log(likelihood.prob)) + log(prior(j));
end
[mx,mxind] = max(posterior);
predictedLabel(i) = classlbl(mxind);
end
accuracy = sum(strcmp(predictedLabel',testingLabels))/numel(testingLabels);

採用された回答

Walter Roberson
Walter Roberson 2015 年 11 月 23 日
  2 件のコメント
Jon Camilleri
Jon Camilleri 2015 年 11 月 23 日
I did not quite find the answer to my question as yet but thanks.
Walter Roberson
Walter Roberson 2015 年 11 月 23 日
The mu are means of each class and the su are standard deviations of each class.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Statistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by