Bayes

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Ejemplo de Bayes

v1

v2

4.5
4
3.5
3
2.5
2
1.5
1
0.5
0

0.5

1.5

2.5

3.5

4.5

Probabilidades de ocurrencia de la clase:

p(c1) = 4/19
p(c2) = 5/19
p(c3) = 10/19

Histogramas:
i1 = find(V(:,3)==1)
H1 = zeros(5,5);
for i=1:length(i1);
H1(V(i1(i),1),V(i1(i),2))=H1(V(i1(i),1),V(i1(i),2))+1;
end
H1 =
1
0
1
0
0

0
0
0
0
0

1
0
1
0
0

0
0
0
0
0

0
0
0
0
0

Histogramas:
H2 =
0
0
0
0
0

0
0
0
0
0

0
0
1
0
0

0
1
1
1
0

0
0
1
0
0

0
0
1
1
1

0
0
1
2
1

0
0
1
1
1

0
0
0
0
0

0
0
0
0
0

H3 =

Probabilidades condicionales p(v|ck) :

P1 = H1/sum(H1(:));
P2 = H2/sum(H2(:));
P3 = H3/sum(H3(:));

Probabilidades condicionales p(v|ck) :


P1 =
0.2500
0
0.2500
0
0

0
0
0
0
0

0.2500
0
0.2500
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0.2000
0
0

0
0.2000
0.2000
0.2000
0

0
0
0.2000
0
0

0
0
0.1000
0.1000
0.1000

0
0
0.1000
0.2000
0.1000

0
0
0.1000
0.1000
0.1000

0
0
0
0
0

0
0
0
0
0

P2 =

P3 =

probabilidad p(v)
HV = zeros(5,5);
for i=1:size(V,1);HV(V(i,1),V(i,2))=HV(V(i,1),V(i,2))+1;end
HV =
1
0
2
1
1

0
0
1
2
1

1
0
3
1
1

0
1
1
1
0

0
0
1
0
0

PV = HV/SUM(HV(:))
PV =
0.0526
0
0.1053
0.0526
0.0526

0
0
0.0526
0.1053
0.0526

0.0526
0
0.1579
0.0526
0.0526

0
0.0526
0.0526
0.0526
0

0
0
0.0526
0
0

probabilidades condicionales p(ck|v) = [ p(ck|v) x p(ck) ] / p(v)


>> pc1v = P1*p(1) % falta dividir por PV!!
0.0526
0
0.0526
0
0

0
0
0
0
0

0.0526
0
0.0526
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0.0526
0
0

0
0.0526
0.0526
0.0526
0

0
0
0.0526
0
0

0
0
0
0
0

0
0
0.1053
0
0

0
0.1053
0.1053
0.1053
0

0
0
0.1053
0
0

>> pc2v = P2*p(2)


0
0
0
0
0
>> pc3v = P2*p(3)
0
0
0
0
0

Clasificacin segn Bayes:


C = zeros(5,5)
for i=1:5;for j=1:5
[M,K] = max([pc1v(i,j) pc2v(i,j) pc3v(i,j)]);
C(i,j) = K;
end; end
C =
1
1
1
3
3

1
1
3
3
3

1
1
1
3
3

1
2
2
2
1

1
1
2
1
1

Desempeo:
TB = zeros(3,3);
for i=1:3
ii = find(c==i);
for j=1:3
for k=1:length(ii)
if(C(V(ii(k),1),V(ii(k),2))==j)
TB(i,j)=TB(i,j)+1;
end
end
end
end
TB =
4
1
2

0
4
0

0
0
8

You might also like