scikit-learn/scikit-learn — Issue #487: Precision issue in least_angle.py
Author: plubans580
Created: 2011-12-20 08:33:27+00:00
State: open

On line 192-198 of least_angle.py, there is this code:

# least squares solution
least_squares, info = potrs(L[:n_active, :n_active],
sign_active[:n_active], lower=True)

# is this really needed ?
AA = 1. / np.sqrt(np.sum(least_squares * sign_active[:n_active]))
least_squares *= AA

When there are correlated predictors, instability in the least squares solution can cause the sum np.sum(least_squares * sign_active[:n_active]) to be negative, causing a bunch of nans to hit the rest of the code, ultimately causing the function to raise the following exception:

...
calculator.fit(independentValues, dependentValues)
File "/u/swcontrol/sfw/python/lib/python2.7/site-packages/scikit_learn-0.9-py2.7-solaris-2.10-i86pc.egg/sklearn/linear_model/least_angle.py", line 427, in fit
max_iter=max_iter, eps=self.eps)
File "/u/swcontrol/sfw/python/lib/python2.7/site-packages/scikit_learn-0.9-py2.7-solaris-2.10-i86pc.egg/sklearn/linear_model/least_angle.py", line 158, in lars_path
sign_active[n_active] = np.sign(C_)
ValueError: cannot convert float NaN to integer

It looks like I can get around my particular issue by increasing the 'eps' parameter passed to the constructor, but I thought this was worth bringing up.