From 657454c0e5a73071ec6681a0774fdaa4269adda7 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Fri, 15 Oct 2021 17:52:12 -0400 Subject: [PATCH 1/3] TST Fixes test_rank_deficient_design --- sklearn/linear_model/_least_angle.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index c9137cbf056ec..1d354eef3228e 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,9 @@ def _lars_path_solver( # orthogonal (QR) decomposition of X corr_eq_dir = np.dot(Gram[:n_active, n_active:].T, least_squares) + # Workaround for inconsistent rounding in openblas + 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) From 91f4b03e6a465773d1dbb4aba658bfc879f176ea Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Sat, 16 Oct 2021 13:06:40 -0400 Subject: [PATCH 2/3] Update sklearn/linear_model/_least_angle.py Co-authored-by: Olivier Grisel --- sklearn/linear_model/_least_angle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index 1d354eef3228e..351aa20f549c2 100644 --- a/sklearn/linear_model/_least_angle.py +++ b/sklearn/linear_model/_least_angle.py @@ -727,7 +727,8 @@ def _lars_path_solver( # orthogonal (QR) decomposition of X corr_eq_dir = np.dot(Gram[:n_active, n_active:].T, least_squares) - # Workaround for inconsistent rounding in openblas + # 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)) From dee07424861673b0af57366896fad1d8a94ee986 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Sat, 16 Oct 2021 13:12:37 -0400 Subject: [PATCH 3/3] DOC Adds whats new --- doc/whats_new/v1.0.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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`