summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-08-18 13:46:10 +0200
committermguetlein <martin.guetlein@gmail.com>2011-08-18 13:46:10 +0200
commit3f1714c78e46f391b951b1a01adcd9badc713891 (patch)
tree27c75c6897ebdf24625ca7ebd66e25f0a63388ae
parent6e10dfb139f584a1b2cc53a30881771f67ac6547 (diff)
add npv calculation, add ppv (renamed from precision) and npv to important classificaiton stats
-rwxr-xr-xlib/predictions.rb23
-rwxr-xr-xlib/validation_db.rb5
-rwxr-xr-xreport/report_factory.rb2
3 files changed, 26 insertions, 4 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
diff --git a/report/report_factory.rb b/report/report_factory.rb
index 2a50869..f6f76bd 100755
--- a/report/report_factory.rb
+++ b/report/report_factory.rb
@@ -6,7 +6,7 @@ VAL_ATTR_CV = [ :algorithm_uri, :dataset_uri, :num_folds, :crossvalidation_fold
# selected attributes of interest when performing classification
VAL_ATTR_CLASS = [ :num_instances, :num_unpredicted, :accuracy, :weighted_accuracy, :average_area_under_roc,
- :area_under_roc, :f_measure, :true_positive_rate, :true_negative_rate ]
+ :area_under_roc, :f_measure, :true_positive_rate, :true_negative_rate, :positive_predictive_value, :negative_predictive_value ]
VAL_ATTR_REGR = [ :num_instances, :num_unpredicted, :root_mean_squared_error,
:weighted_root_mean_squared_error, :mean_absolute_error, :weighted_mean_absolute_error, :r_square, :weighted_r_square,
:sample_correlation_coefficient ]