diff options
author | mguetlein <martin.guetlein@gmail.com> | 2011-08-18 13:46:10 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2011-08-18 13:46:10 +0200 |
commit | 3f1714c78e46f391b951b1a01adcd9badc713891 (patch) | |
tree | 27c75c6897ebdf24625ca7ebd66e25f0a63388ae /lib/predictions.rb | |
parent | 6e10dfb139f584a1b2cc53a30881771f67ac6547 (diff) |
add npv calculation, add ppv (renamed from precision) and npv to important classificaiton stats
Diffstat (limited to 'lib/predictions.rb')
-rwxr-xr-x | lib/predictions.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/predictions.rb b/lib/predictions.rb index 7de1751..2e90885 100755 --- a/lib/predictions.rb +++ b/lib/predictions.rb @@ -300,7 +300,11 @@ module Lib end def precision(class_index=nil) - return prediction_feature_value_map( lambda{ |i| precision(i) } ) if class_index==nil + return positive_predictive_value(class_index) + end + + def positive_predictive_value(class_index=nil) + return prediction_feature_value_map( lambda{ |i| positive_predictive_value(i) } ) if class_index==nil correct = 0 # all instances with prediction class_index that are correctly classified total = 0 # all instances with prediciton class_index @@ -312,6 +316,23 @@ module Lib return correct/total.to_f end + def negative_predictive_value(class_index=nil) + return prediction_feature_value_map( lambda{ |i| negative_predictive_value(i) } ) if class_index==nil + + correct = 0 # all instances with prediction class_index that are correctly classified + total = 0 # all instances with prediciton class_index + (0..@num_classes-1).each do |i| + if i != class_index + (0..@num_classes-1).each do |j| + correct += @confusion_matrix[j][i] if j != class_index + total += @confusion_matrix[j][i] + end + end + end + return 0 if total==0 + return correct/total.to_f + end + def recall(class_index=nil) return true_positive_rate(class_index) end |