clear % evaluate P(Ai | Vj ) from 'textdata.nominal.txt' for naive bayes classifer % i = 1..18 and A1 = 'S2', 'S1', 'CE', 'B1' or 'B2' and ... % j = 1,2 and Vj = 'yes' or 'no' [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, target] = ... textread('textdata.nominal.txt','%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s','delimiter',','); yes_index = find(strcmp(target,'yes')==1); no_index = find(strcmp(target,'no')==1); % m-estimate of probability is used where m = 5 and p = 1/5 for each Ai % P(i,j,k) for i = 1,2, ...18 and j = 1,2,...5 and k = 1,2 % where L1='S2', L2='S1', L3='CE', L4='B1' and L5='B2' % V1 = 'Yes' and V2 = 'No' % means P(Ai = Lj | Vk ) for i1 = 1:18 Ai_yes = eval(sprintf('A%d(yes_index)',i1)); Ai_no = eval(sprintf('A%d(no_index)',i1)); P(i1,1,1) = (length(find(strcmp(Ai_yes,'S2')==1)) + .2) / (length(yes_index) + 1); P(i1,2,1) = (length(find(strcmp(Ai_yes,'S1')==1)) + .2) / (length(yes_index) + 1); P(i1,3,1) = (length(find(strcmp(Ai_yes,'CE')==1)) + .2) / (length(yes_index) + 1); P(i1,4,1) = (length(find(strcmp(Ai_yes,'B1')==1)) + .2) / (length(yes_index) + 1); P(i1,5,1) = (length(find(strcmp(Ai_yes,'B2')==1)) + .2) / (length(yes_index) + 1); P(i1,1,2) = (length(find(strcmp(Ai_no,'S2')==1)) + .2) / (length(no_index) + 1); P(i1,2,2) = (length(find(strcmp(Ai_no,'S1')==1)) + .2) / (length(no_index) + 1); P(i1,3,2) = (length(find(strcmp(Ai_no,'CE')==1)) + .2) / (length(no_index) + 1); P(i1,4,2) = (length(find(strcmp(Ai_no,'B1')==1)) + .2) / (length(no_index) + 1); P(i1,5,2) = (length(find(strcmp(Ai_no,'B2')==1)) + .2) / (length(no_index) + 1); end clear A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18 yes_index no_index Ai_yes Ai_no target i1 save text_probs