scikit-learn/scikit-learn — pull request #711 by davidmarek (2012-03-18 22:43:52+00:00)
Title: fixed SparsePCA.transform returning NaN for 0 feature in all samples. (fixes #615)

I fixed the division (#615) by first checking if there are any zeros in the denominator. This error happens only when all samples have output feature which is always 0. I set all zeros to 1 and the resulting division then will be 0/1, which yields the correct value: 0.

I know there are many ways how to fix this bug. At first I tried to replace the NaNs after the division, but numpy would print RuntimeWarning and I think it would be bad idea to turn them off.