Guest User

Untitled

a guest
Jul 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. def prune_stat(root, nodes, examples)
  2.  
  3.  
  4. nodes.each_index { | i |
  5.  
  6. if nodes[i].leaf then
  7. next
  8. end
  9.  
  10. # otherwise check if can be pruned
  11. check_prune = false
  12. nodes[i].children.each_index{ | j |
  13. if nodes[i].children[j].leaf then
  14.  
  15. check_prune = true
  16. end
  17. }
  18.  
  19.  
  20. total = 0
  21. if check_prune then
  22. puts "HJERE"
  23. if(nodes[i].npos == 0 and nodes[i].nneg == 0 ) then
  24. puts "UNEXPECTED ERROR"
  25. a = gets.chomp!
  26. end
  27.  
  28. size = nodes[i].npos + nodes[i].nneg
  29.  
  30.  
  31. nodes[i].children.each_index{ | j |
  32.  
  33. sum = 0
  34. p = nodes[i].children[j].npos + nodes[i].children[j].nneg
  35. p = (1.0 * p )/ size
  36.  
  37. p =
  38. sum += ( ( nodes[i].children[j].npos - p * node[i].npos )**2 ) / (p * node[i].npos)
  39. sum += ( ( nodes[i].children[j].nneg - p * node[i].nneg )**2 ) / (p * node[i].nneg )
  40.  
  41. total += sum
  42. }
  43.  
  44.  
  45. if total < THRESHOLD then
  46. nodes[i].leaf = true
  47. nodes[i].label = nodes[i].most_common
  48.  
  49. puts "PRUNED"
  50.  
  51. correct = total = acc = 0
  52. examples.each_index{ | k |
  53. classification = report_acc( root, examples[k] )
  54.  
  55. if( examples[i].label == classification ) then
  56. correct += 1
  57. end
  58.  
  59. total += 1
  60.  
  61. }
  62.  
  63. acc = (1.0 * correct) / ( total )
  64. print acc
  65. puts
  66.  
  67. return true
  68. end
  69.  
  70.  
  71. end
  72.  
  73. return false
  74. }
  75.  
  76.  
  77. end
Add Comment
Please, Sign In to add comment