diff options
author | mguetlein <martin.guetlein@gmail.com> | 2011-07-12 11:41:32 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2011-07-12 11:41:32 +0200 |
commit | d0f50a2218fca7580be80e0595b0a73069329ad6 (patch) | |
tree | eb897a3cbe5e8e6a4242c489635a7bca55643027 /lib/predictions.rb | |
parent | 9407fcd5c937370324764a08afd589f386e83b60 (diff) |
fixed sqrt domain error in regression validation, added check for NaN and Infinity
Diffstat (limited to 'lib/predictions.rb')
-rwxr-xr-x | lib/predictions.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/predictions.rb b/lib/predictions.rb index 082ad10..f4fb461 100755 --- a/lib/predictions.rb +++ b/lib/predictions.rb @@ -59,7 +59,7 @@ module Lib raise "accept_values != nil while performing regression" if @accept_values { "predicted"=>@predicted_values, "actual"=>@actual_values }.each do |s,values| values.each{ |v| raise "illegal "+s+" regression-value ("+v.to_s+"),"+ - "has to be either nil or number" unless v==nil or v.is_a?(Numeric)} + "has to be either nil or number (not NaN, not Infinite)" if v!=nil and (!v.is_a?(Numeric) or v.nan? or v.finite?)} end end @@ -471,7 +471,9 @@ module Lib public def root_mean_squared_error return 0 if (@num_with_actual_value - @num_unpredicted)==0 - Math.sqrt(@sum_squared_error / (@num_with_actual_value - @num_unpredicted).to_f) + mse = @sum_squared_error / (@num_with_actual_value - @num_unpredicted).to_f + return 0 if mse.nan? + Math.sqrt(mse) end def weighted_root_mean_squared_error |