Advertisement
Guest User

Untitled

a guest
May 4th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. FK0
  2. var = 2080.1
  3. med = 165.72
  4. apri0 = 0.14085
  5.  
  6. FK1
  7. var = 3864.9
  8. med = 217.92
  9. apri1 = 0.16901
  10.  
  11. FK2
  12. var = 3631.9
  13. med = 244.64
  14. apri2 = 0.19718
  15.  
  16. FK3
  17. var = 3248.3
  18. med = 325.60
  19. apri3 = 0.16901
  20.  
  21. FK4
  22. var = 5336.4
  23. med = 281.82
  24. apri4 = 0.15493
  25.  
  26. FK5
  27. var = 4829.6
  28. med = 326.93
  29. apri5 = 0.16901
  30.  
  31. Für k = 1
  32.  
  33. confusionmatrix =
  34.  
  35. 4 3 0 0 3 0
  36. 5 6 1 0 0 0
  37. 2 2 5 2 3 0
  38. 0 1 3 4 2 2
  39. 3 1 1 4 1 1
  40. 0 3 3 5 0 1
  41.  
  42. guete = 0.29577
  43.  
  44. Für k = 3
  45. confusionmatrix =
  46.  
  47. 7 1 1 0 1 0
  48. 6 5 1 0 0 0
  49. 3 3 4 2 2 0
  50. 1 2 3 5 0 1
  51. 4 1 3 3 0 0
  52. 1 2 3 3 1 2
  53.  
  54. guete = 0.32394
  55.  
  56. Für k = 5
  57. confusionmatrix =
  58.  
  59. 7 0 1 0 2 0
  60. 6 3 0 1 2 0
  61. 4 4 6 0 0 0
  62. 0 0 2 8 1 1
  63. 2 2 2 4 1 0
  64. 1 1 3 3 0 4
  65.  
  66. guete = 0.40845
  67.  
  68.  
  69. SOURCE
  70.  
  71. Training = load("chickwts_training.csv")
  72. Testing = load("chickwts_testing.csv")
  73.  
  74.  
  75.  
  76. function [tmp] = dist(huhn, Training) #Sortiert Training nach Spalte 2 in der der Abstand zu Huhn steht
  77. tmp = Training
  78. tmp(:,2) = abs(Training(:,2)-huhn(1,2)) #Distanzen berechnen und in tmp eintragen
  79. tmp = sortrows(tmp,2) #Sortiere nach Distanz zu Alphahuhn!
  80. endfunction
  81.  
  82. function [class] = vote(k,Ranking)
  83. classes = [0,0,0,0,0,0]
  84. for in = 1:k
  85. ind = Ranking(in,3)+1 #Wegen Klasse 0 eines draufzählen
  86. classes(1,ind)=(classes(1,ind)+1)
  87. endfor
  88. [value,class] = max(classes)
  89. class = class-1 #Wieder abziehen wegen der 0 vorher.
  90. endfunction
  91.  
  92. function [chicks] = classify(k,NeueHuehner,Training)
  93. chicks = resize(NeueHuehner,rows(NeueHuehner),(columns(NeueHuehner)+1)) #Neue Spalte anfügen
  94. for i = 1:rows(NeueHuehner)
  95. chicks(i,4) = vote(k,dist(NeueHuehner(i,:),Training)) #Voten, welcher Klasse das Huhn angehört
  96. endfor
  97. endfunction
  98.  
  99. function [confusionmatrix,guete] = confusion(chicks)
  100. confusionmatrix = zeros(6,6) # Leere Matrix
  101. for i = 1:rows(chicks)
  102. #x = Klasse die Richtig wäre
  103. #y = Als was wurde es klassifiziert?
  104. x = chicks(i,3)+1 #Die gleiche Sache mit Klasse 0
  105. y = chicks(i,4)+1
  106. confusionmatrix(x,y) = confusionmatrix(x,y) +1
  107. endfor
  108. guete = sum(diag(confusionmatrix))/rows(chicks) #Auf der Diagonale stehen die Richtigen
  109. endfunction
  110.  
  111.  
  112. FUKL0=Training(Training(:,3)==0,:)
  113. FUKL1=Training(Training(:,3)==1,:)
  114. FUKL2=Training(Training(:,3)==2,:)
  115. FUKL3=Training(Training(:,3)==3,:)
  116. FUKL4=Training(Training(:,3)==4,:)
  117. FUKL5=Training(Training(:,3)==5,:)
  118.  
  119. var(FUKL0(:,2))
  120. mean((FUKL0(:,2)))
  121. apri0=rows(FUKL0)/rows(Training)
  122. var(FUKL1(:,2))
  123. mean((FUKL1(:,2)))
  124. apri1=rows(FUKL1)/rows(Training)
  125. var(FUKL2(:,2))
  126. mean((FUKL2(:,2)))
  127. apri2=rows(FUKL2)/rows(Training)
  128. var(FUKL3(:,2))
  129. mean((FUKL3(:,2)))
  130. apri3=rows(FUKL3)/rows(Training)
  131. var(FUKL4(:,2))
  132. mean((FUKL4(:,2)))
  133. apri4=rows(FUKL4)/rows(Training)
  134. var(FUKL5(:,2))
  135. mean((FUKL5(:,2)))
  136. apri5=rows(FUKL5)/rows(Training)
  137. #Beispielabfrage: confusion(classify(3,Testing, Training))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement