diff options
author | mguetlein <martin.guetlein@gmail.com> | 2011-07-18 09:34:52 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2011-07-18 09:34:52 +0200 |
commit | db4f1b61f588bfb59f161763922199c8a07d7a56 (patch) | |
tree | 0a5e666d34a0c3dd3acf41e420bf91d4fae7d309 | |
parent | e0ff256a0a4508b2c4e250e7b02aa9b3099d9abb (diff) |
resuce correlation coeffiction computation errors
-rwxr-xr-x | lib/predictions.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/predictions.rb b/lib/predictions.rb index a4c57a0..b71359d 100755 --- a/lib/predictions.rb +++ b/lib/predictions.rb @@ -517,11 +517,13 @@ module Lib end def sample_correlation_coefficient - # formula see http://en.wikipedia.org/wiki/Correlation_and_dependence#Pearson.27s_product-moment_coefficient - scc = ( @num_predicted * @sum_multiply - @sum_actual * @sum_predicted ) / - ( Math.sqrt( [0, @num_predicted * @sum_squares_actual - @sum_actual**2].max ) * - Math.sqrt( [0, @num_predicted * @sum_squares_predicted - @sum_predicted**2].max ) ) - ( scc.infinite? || scc.nan? ) ? 0 : scc + begin + # formula see http://en.wikipedia.org/wiki/Correlation_and_dependence#Pearson.27s_product-moment_coefficient + scc = ( @num_predicted * @sum_multiply - @sum_actual * @sum_predicted ) / + ( Math.sqrt( @num_predicted * @sum_squares_actual - @sum_actual**2 ) * + Math.sqrt( @num_predicted * @sum_squares_predicted - @sum_predicted**2 ) ) + ( scc.infinite? || scc.nan? ) ? 0 : scc + rescue; 0; end end def total_sum_of_squares |