Aim:- Write
a program for Bayes classification algorithm.
Tools:
-MATLAB
Theory:
-
Bayesian
reasoning is applied to decision making and inferential statistics that deals
with probability inference. It is used the knowledge of prior events to predict
future events.
The Bayes Theorem: P(h/D)= P(D/h) P(h) / P(D)
Where;
P(h) : Prior probability of hypothesis h
P(D)
: Prior probability of training data D
P(h/D)
: Probability of h given D
P(D/h)
: Probability of D given h
Program:-
Example:- Consider the Following vector (likes shortbread, likes burger,
eats porridge, watched england play football, nationality).
Now, Nationality is Scottish and England. For Scottish
1 and for England 0.
X =
[ 0 0 1 1 0 ;
1 0
1 0 0 ;
1 1
0 1 0 ;
1 1
0 0 0 ;
0 1
0 1 0 ;
0 0
1 0 0 ;
1 0
1 1 1 ;
1 1
0 1 1 ;
1 1
1 0 1 ;
1 1
1 0 1 ;
1 1
1 1 1 ;
1 0
1 0 1 ;
1 0
0 0 1 ];
Y =
X(:,5);
X =
X(:,1:4)';
pS =
sum (Y)/size(Y,1);
pE =
sum(1 - Y)/size(Y,1);
phiS
= X * Y / sum(Y);
phiE
= X * (1-Y) / sum(1-Y) ;
x=[1
0 1 0]';
pxS
= prod(phiS.^x.*(1-phiS).^(1-x));
pxE
= prod(phiE.^x.*(1-phiE).^(1-x));
pxSF
= (pxS * pS ) / (pxS + pxE)
0 Comments