summaryrefslogtreecommitdiff
path: root/lib/predictions.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/predictions.rb')
-rwxr-xr-xlib/predictions.rb23
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