Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def prune_stat(root, nodes, examples)
- nodes.each_index { | i |
- if nodes[i].leaf then
- next
- end
- # otherwise check if can be pruned
- check_prune = false
- nodes[i].children.each_index{ | j |
- if nodes[i].children[j].leaf then
- check_prune = true
- end
- }
- total = 0
- if check_prune then
- puts "HJERE"
- if(nodes[i].npos == 0 and nodes[i].nneg == 0 ) then
- puts "UNEXPECTED ERROR"
- a = gets.chomp!
- end
- size = nodes[i].npos + nodes[i].nneg
- nodes[i].children.each_index{ | j |
- sum = 0
- p = nodes[i].children[j].npos + nodes[i].children[j].nneg
- p = (1.0 * p )/ size
- p =
- sum += ( ( nodes[i].children[j].npos - p * node[i].npos )**2 ) / (p * node[i].npos)
- sum += ( ( nodes[i].children[j].nneg - p * node[i].nneg )**2 ) / (p * node[i].nneg )
- total += sum
- }
- if total < THRESHOLD then
- nodes[i].leaf = true
- nodes[i].label = nodes[i].most_common
- puts "PRUNED"
- correct = total = acc = 0
- examples.each_index{ | k |
- classification = report_acc( root, examples[k] )
- if( examples[i].label == classification ) then
- correct += 1
- end
- total += 1
- }
- acc = (1.0 * correct) / ( total )
- print acc
- puts
- return true
- end
- end
- return false
- }
- end
Add Comment
Please, Sign In to add comment