summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-02-03 18:14:20 +0100
committermguetlein <martin.guetlein@gmail.com>2011-02-03 18:14:20 +0100
commitaca886bf82e7ebf5a9d76642614418ed983ab45e (patch)
treebdd9b22fccfff637dddd0b10d4800a8e41fe8382 /lib
parent7906047a423d94692581ac6aa15295924c8b89db (diff)
adding weighted_accuracy, change accuracy computation, some minor changes
Diffstat (limited to 'lib')
-rwxr-xr-xlib/ot_predictions.rb4
-rwxr-xr-xlib/predictions.rb21
-rwxr-xr-xlib/validation_db.rb3
3 files changed, 23 insertions, 5 deletions
diff --git a/lib/ot_predictions.rb b/lib/ot_predictions.rb
index e28f35b..b0e9720 100755
--- a/lib/ot_predictions.rb
+++ b/lib/ot_predictions.rb
@@ -165,7 +165,9 @@ module Lib
end
raise "no array" unless v.is_a?(Array)
if v.size>1
- raise "multiple values"
+ v.uniq!
+ raise "not yet implemented: multiple non-equal values "+compound.to_s+" "+v.inspect if v.size>1
+ v = v[0]
elsif v.size==1
v = v[0]
else
diff --git a/lib/predictions.rb b/lib/predictions.rb
index e73dda6..5850024 100755
--- a/lib/predictions.rb
+++ b/lib/predictions.rb
@@ -163,19 +163,36 @@ module Lib
def percent_correct
raise "no classification" unless @feature_type=="classification"
return 0 if @num_with_actual_value==0
- return 100 * @num_correct / @num_with_actual_value.to_f
+ return 100 * @num_correct / (@num_with_actual_value - @num_unpredicted).to_f
end
def percent_incorrect
raise "no classification" unless @feature_type=="classification"
return 0 if @num_with_actual_value==0
- return 100 * @num_incorrect / @num_with_actual_value.to_f
+ return 100 * @num_incorrect / (@num_with_actual_value - @num_unpredicted).to_f
end
def accuracy
return percent_correct / 100.0
end
+ def weighted_accuracy
+ raise "no classification" unless @feature_type=="classification"
+ total = 0
+ correct = 0
+ (0..@predicted_values.size-1).each do |i|
+ if @predicted_values[i]!=nil
+ total += @confidence_values[i]
+ correct += @confidence_values[i] if @actual_values[i]==@predicted_values[i]
+ end
+ end
+ if total==0 || correct == 0
+ return 0
+ else
+ return correct / total
+ end
+ end
+
def percent_unpredicted
return 0 if @num_with_actual_value==0
return 100 * @num_unpredicted / @num_with_actual_value.to_f
diff --git a/lib/validation_db.rb b/lib/validation_db.rb
index 4b852f9..c4cb2a2 100755
--- a/lib/validation_db.rb
+++ b/lib/validation_db.rb
@@ -18,10 +18,9 @@ module Lib
# :classification_statistics
VAL_CLASS_PROPS_SINGLE_SUM = [ :num_correct, :num_incorrect, :confusion_matrix ]
VAL_CLASS_PROPS_SINGLE_AVG = [ :percent_correct, :percent_incorrect,
- :weighted_area_under_roc, :accuracy ]
+ :weighted_area_under_roc, :accuracy, :weighted_accuracy ]
VAL_CLASS_PROPS_SINGLE = VAL_CLASS_PROPS_SINGLE_SUM + VAL_CLASS_PROPS_SINGLE_AVG
-
# :class_value_statistics
VAL_CLASS_PROPS_PER_CLASS_SUM = [ :num_false_positives, :num_false_negatives,
:num_true_positives, :num_true_negatives ]