scikit-learn/scikit-learn — pull request #2158 by jzwinck (2013-07-16 06:36:30+00:00)
Title: Use float64 inside metrics.r2_score() to preserve FP accuracy

Without this, if the input arrays are of type np.float32, their sums may be computed with an large accumulated error, resulting in the wrong score. This can often be seen with very long arrays (millions of elements). The "1 - numerator / denominator" calculation at the very end produces a float64 when the inputs are float32 anyway, so the returned type does not change--only the accuracy.

The existing metrics tests pass after this change; someone may with to further review other uses of sum() in this file and elsewhere to see if similar improvements can be made.