diff options
author | mguetlein <martin.guetlein@gmail.com> | 2011-02-03 18:14:20 +0100 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2011-02-03 18:14:20 +0100 |
commit | aca886bf82e7ebf5a9d76642614418ed983ab45e (patch) | |
tree | bdd9b22fccfff637dddd0b10d4800a8e41fe8382 /lib/predictions.rb | |
parent | 7906047a423d94692581ac6aa15295924c8b89db (diff) |
adding weighted_accuracy, change accuracy computation, some minor changes
Diffstat (limited to 'lib/predictions.rb')
-rwxr-xr-x | lib/predictions.rb | 21 |
1 files changed, 19 insertions, 2 deletions
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 |