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 | |
parent | 6e10dfb139f584a1b2cc53a30881771f67ac6547 (diff) |
add npv calculation, add ppv (renamed from precision) and npv to important classificaiton stats
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/predictions.rb | 23 | ||||
-rwxr-xr-x | lib/validation_db.rb | 5 |
2 files changed, 25 insertions, 3 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 diff --git a/lib/validation_db.rb b/lib/validation_db.rb index 9af43de..be004fb 100755 --- a/lib/validation_db.rb +++ b/lib/validation_db.rb @@ -25,12 +25,13 @@ module Validation VAL_CLASS_PROPS_PER_CLASS_SUM = [ :num_false_positives, :num_false_negatives, :num_true_positives, :num_true_negatives ] VAL_CLASS_PROPS_PER_CLASS_AVG = [ :area_under_roc, :false_negative_rate, :false_positive_rate, - :f_measure, :precision, + :f_measure, :positive_predictive_value, :negative_predictive_value, :true_negative_rate, :true_positive_rate ] #:recall, VAL_CLASS_PROPS_PER_CLASS = VAL_CLASS_PROPS_PER_CLASS_SUM + VAL_CLASS_PROPS_PER_CLASS_AVG VAL_CLASS_PROPS_PER_CLASS_COMPLEMENT_EXISTS = [ :num_false_positives, :num_false_negatives, :num_true_positives, :num_true_negatives, :false_negative_rate, :false_positive_rate, - :true_negative_rate, :true_positive_rate, :area_under_roc ] #:precision, :recall, + :true_negative_rate, :true_positive_rate, :area_under_roc, + :positive_predictive_value, :negative_predictive_value ] #:precision, :recall, VAL_CLASS_PROPS = VAL_CLASS_PROPS_SINGLE + VAL_CLASS_PROPS_PER_CLASS |