diff --git a/doc/whats_new/v1.0.rst b/doc/whats_new/v1.0.rst index 84a86dc688aa9..25d6e95064a09 100644 --- a/doc/whats_new/v1.0.rst +++ b/doc/whats_new/v1.0.rst @@ -43,6 +43,12 @@ Fixed models between sparse and dense input. :pr:`21195` by :user:`Jérémie du Boisberranger `. +:mod:`sklearn.linear_model` +........................... + +- |Fix| Improves stability of :class:`linear_model.LassoLars` for different + versions of openblas. :pr:`21340` by `Thomas Fan`_. + :mod:`sklearn.neighbors` ........................ @@ -677,7 +683,7 @@ Changelog Dupre la Tour`_. - |Fix| Decrease the numerical default tolerance in the lobpcg call - in :func:`manifold.spectral_embedding` to prevent numerical instability. + in :func:`manifold.spectral_embedding` to prevent numerical instability. :pr:`21194` by :user:`Andrew Knyazev `. :mod:`sklearn.metrics` diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index c9137cbf056ec..351aa20f549c2 100644 --- a/sklearn/linear_model/_least_angle.py +++ b/sklearn/linear_model/_least_angle.py @@ -544,6 +544,7 @@ def _lars_path_solver( sys.stdout.flush() tiny32 = np.finfo(np.float32).tiny # to avoid division by 0 warning + cov_precision = np.finfo(Cov.dtype).precision equality_tolerance = np.finfo(np.float32).eps if Gram is not None: @@ -726,6 +727,10 @@ def _lars_path_solver( # orthogonal (QR) decomposition of X corr_eq_dir = np.dot(Gram[:n_active, n_active:].T, least_squares) + # Explicit rounding can be necessary to avoid `np.argmax(Cov)` yielding + # unstable results because of rounding errors. + np.around(corr_eq_dir, decimals=cov_precision, out=corr_eq_dir) + g1 = arrayfuncs.min_pos((C - Cov) / (AA - corr_eq_dir + tiny32)) if positive: gamma_ = min(g1, C / AA)