Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FK0
- var = 2080.1
- med = 165.72
- apri0 = 0.14085
- FK1
- var = 3864.9
- med = 217.92
- apri1 = 0.16901
- FK2
- var = 3631.9
- med = 244.64
- apri2 = 0.19718
- FK3
- var = 3248.3
- med = 325.60
- apri3 = 0.16901
- FK4
- var = 5336.4
- med = 281.82
- apri4 = 0.15493
- FK5
- var = 4829.6
- med = 326.93
- apri5 = 0.16901
- Für k = 1
- confusionmatrix =
- 4 3 0 0 3 0
- 5 6 1 0 0 0
- 2 2 5 2 3 0
- 0 1 3 4 2 2
- 3 1 1 4 1 1
- 0 3 3 5 0 1
- guete = 0.29577
- Für k = 3
- confusionmatrix =
- 7 1 1 0 1 0
- 6 5 1 0 0 0
- 3 3 4 2 2 0
- 1 2 3 5 0 1
- 4 1 3 3 0 0
- 1 2 3 3 1 2
- guete = 0.32394
- Für k = 5
- confusionmatrix =
- 7 0 1 0 2 0
- 6 3 0 1 2 0
- 4 4 6 0 0 0
- 0 0 2 8 1 1
- 2 2 2 4 1 0
- 1 1 3 3 0 4
- guete = 0.40845
- SOURCE
- Training = load("chickwts_training.csv")
- Testing = load("chickwts_testing.csv")
- function [tmp] = dist(huhn, Training) #Sortiert Training nach Spalte 2 in der der Abstand zu Huhn steht
- tmp = Training
- tmp(:,2) = abs(Training(:,2)-huhn(1,2)) #Distanzen berechnen und in tmp eintragen
- tmp = sortrows(tmp,2) #Sortiere nach Distanz zu Alphahuhn!
- endfunction
- function [class] = vote(k,Ranking)
- classes = [0,0,0,0,0,0]
- for in = 1:k
- ind = Ranking(in,3)+1 #Wegen Klasse 0 eines draufzählen
- classes(1,ind)=(classes(1,ind)+1)
- endfor
- [value,class] = max(classes)
- class = class-1 #Wieder abziehen wegen der 0 vorher.
- endfunction
- function [chicks] = classify(k,NeueHuehner,Training)
- chicks = resize(NeueHuehner,rows(NeueHuehner),(columns(NeueHuehner)+1)) #Neue Spalte anfügen
- for i = 1:rows(NeueHuehner)
- chicks(i,4) = vote(k,dist(NeueHuehner(i,:),Training)) #Voten, welcher Klasse das Huhn angehört
- endfor
- endfunction
- function [confusionmatrix,guete] = confusion(chicks)
- confusionmatrix = zeros(6,6) # Leere Matrix
- for i = 1:rows(chicks)
- #x = Klasse die Richtig wäre
- #y = Als was wurde es klassifiziert?
- x = chicks(i,3)+1 #Die gleiche Sache mit Klasse 0
- y = chicks(i,4)+1
- confusionmatrix(x,y) = confusionmatrix(x,y) +1
- endfor
- guete = sum(diag(confusionmatrix))/rows(chicks) #Auf der Diagonale stehen die Richtigen
- endfunction
- FUKL0=Training(Training(:,3)==0,:)
- FUKL1=Training(Training(:,3)==1,:)
- FUKL2=Training(Training(:,3)==2,:)
- FUKL3=Training(Training(:,3)==3,:)
- FUKL4=Training(Training(:,3)==4,:)
- FUKL5=Training(Training(:,3)==5,:)
- var(FUKL0(:,2))
- mean((FUKL0(:,2)))
- apri0=rows(FUKL0)/rows(Training)
- var(FUKL1(:,2))
- mean((FUKL1(:,2)))
- apri1=rows(FUKL1)/rows(Training)
- var(FUKL2(:,2))
- mean((FUKL2(:,2)))
- apri2=rows(FUKL2)/rows(Training)
- var(FUKL3(:,2))
- mean((FUKL3(:,2)))
- apri3=rows(FUKL3)/rows(Training)
- var(FUKL4(:,2))
- mean((FUKL4(:,2)))
- apri4=rows(FUKL4)/rows(Training)
- var(FUKL5(:,2))
- mean((FUKL5(:,2)))
- apri5=rows(FUKL5)/rows(Training)
- #Beispielabfrage: confusion(classify(3,Testing, Training))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement