From 940b5b9e11c6443b6a3ac9882b07e4d9253b8555 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Thu, 27 May 2021 15:38:51 +0900 Subject: [PATCH 01/18] Add test case to confirm input/output type match --- sklearn/linear_model/tests/test_least_angle.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 4321c39b45e92..bffe71009822a 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -777,3 +777,14 @@ def test_copy_X_with_auto_gram(): linear_model.lars_path(X, y, Gram='auto', copy_X=True, method='lasso') # X did not change assert_allclose(X, X_before) + +def test_lars_dtype_match(): + rng = np.random.RandomState(0) + X = rng.rand(6, 6).astype(np.float32) + Y = rng.rand(6).astype(np.float32) + + model = Lars(n_nonzero_coefs=1) + model.fit(X,Y) + assert model.coef_.dtype == np.float32 + assert model.coef_path_.dtype == np.float32 + assert model.intercept_.dtype == np.float32 From d7a53f8195760f93a1536513839ec010a57ea952 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Thu, 27 May 2021 16:46:46 +0900 Subject: [PATCH 02/18] Add test case --- .../linear_model/tests/test_least_angle.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index bffe71009822a..d0a24d55813f4 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -778,13 +778,19 @@ def test_copy_X_with_auto_gram(): # X did not change assert_allclose(X, X_before) -def test_lars_dtype_match(): + +@pytest.mark.parametrize("x_data_type, y_data_type, expected_type", ( + (np.float32, np.float32, np.float32), + (np.float64, np.float64, np.float64))) +def test_lars_dtype_match(x_data_type, y_data_type, expected_type): rng = np.random.RandomState(0) - X = rng.rand(6, 6).astype(np.float32) - Y = rng.rand(6).astype(np.float32) - - model = Lars(n_nonzero_coefs=1) - model.fit(X,Y) - assert model.coef_.dtype == np.float32 - assert model.coef_path_.dtype == np.float32 - assert model.intercept_.dtype == np.float32 + X = rng.rand(6, 6).astype(x_data_type) + y = rng.rand(6).astype(y_data_type) + + model = Lars() + model.fit(X, y) + assert model.coef_.dtype == expected_type + # coef_path_ can be list of array + for coef in model.coef_path_: + assert coef.dtype == expected_type + assert model.intercept_.dtype == expected_type From 2a4de87385e825bac1874f7498068f68780d959a Mon Sep 17 00:00:00 2001 From: takoika <> Date: Thu, 27 May 2021 16:49:52 +0900 Subject: [PATCH 03/18] Set empty array's dtype from input array --- sklearn/linear_model/_least_angle.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index 0932d0bd1aee3..2762efc299bfd 100644 --- a/sklearn/linear_model/_least_angle.py +++ b/sklearn/linear_model/_least_angle.py @@ -476,12 +476,21 @@ def _lars_path_solver( max_features = min(max_iter, n_features) + return_dtype = np.float64 + for input_array in (X, y, Xy, Gram): + if input_array is not None: + return_dtype = input_array.dtype + break + if return_path: - coefs = np.zeros((max_features + 1, n_features)) - alphas = np.zeros(max_features + 1) + coefs = np.zeros((max_features + 1, n_features), dtype=return_dtype) + alphas = np.zeros(max_features + 1, dtype=return_dtype) else: - coef, prev_coef = np.zeros(n_features), np.zeros(n_features) - alpha, prev_alpha = np.array([0.]), np.array([0.]) # better ideas? + coef, prev_coef = (np.zeros(n_features, dtype=return_dtype), + np.zeros(n_features, dtype=return_dtype)) + alpha, prev_alpha = (np.array([0.], dtype=return_dtype), + np.array([0.], dtype=return_dtype)) + # above better ideas? n_iter, n_active = 0, 0 active, indices = list(), np.arange(n_features) @@ -948,7 +957,7 @@ def _fit(self, X, y, max_iter, alpha, fit_path, Xy=None): self.alphas_ = [] self.n_iter_ = [] - self.coef_ = np.empty((n_targets, n_features)) + self.coef_ = np.empty((n_targets, n_features), dtype=X.dtype) if fit_path: self.active_ = [] From 23885aabdd5b59964656a182617b17df227e7fe7 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Thu, 27 May 2021 16:56:05 +0900 Subject: [PATCH 04/18] Add test cases --- sklearn/linear_model/tests/test_least_angle.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index d0a24d55813f4..5afc573291936 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -778,19 +778,20 @@ def test_copy_X_with_auto_gram(): # X did not change assert_allclose(X, X_before) - +@pytest.mark.parametrize("LARS", (Lars, LassoLars, LassoLarsIC)) @pytest.mark.parametrize("x_data_type, y_data_type, expected_type", ( (np.float32, np.float32, np.float32), (np.float64, np.float64, np.float64))) -def test_lars_dtype_match(x_data_type, y_data_type, expected_type): +def test_lars_dtype_match(LARS, x_data_type, y_data_type, expected_type): rng = np.random.RandomState(0) X = rng.rand(6, 6).astype(x_data_type) y = rng.rand(6).astype(y_data_type) - model = Lars() + model = LARS() model.fit(X, y) assert model.coef_.dtype == expected_type - # coef_path_ can be list of array - for coef in model.coef_path_: - assert coef.dtype == expected_type + if hasattr(model, "coef_path_"): + # coef_path_ can be list of array + for coef in model.coef_path_: + assert coef.dtype == expected_type assert model.intercept_.dtype == expected_type From d13de624d4f9ffe9503cd52ba45fd5b6813d61f7 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Thu, 27 May 2021 18:03:55 +0900 Subject: [PATCH 05/18] Address E302 --- sklearn/linear_model/tests/test_least_angle.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 5afc573291936..6eae0e2a0a341 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -778,6 +778,7 @@ def test_copy_X_with_auto_gram(): # X did not change assert_allclose(X, X_before) + @pytest.mark.parametrize("LARS", (Lars, LassoLars, LassoLarsIC)) @pytest.mark.parametrize("x_data_type, y_data_type, expected_type", ( (np.float32, np.float32, np.float32), From ac598011d900411d74b8bfe9d766fcbc84009b3c Mon Sep 17 00:00:00 2001 From: takoika <> Date: Thu, 27 May 2021 18:33:23 +0900 Subject: [PATCH 06/18] Test numerical consistency betwenn float32 and float64 --- sklearn/linear_model/tests/test_least_angle.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 6eae0e2a0a341..1ba7aa280dbd0 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -796,3 +796,18 @@ def test_lars_dtype_match(LARS, x_data_type, y_data_type, expected_type): for coef in model.coef_path_: assert coef.dtype == expected_type assert model.intercept_.dtype == expected_type + + +@pytest.mark.parametrize("LARS", (Lars, LassoLars, LassoLarsIC)) +def test_lars_numeric_consistency(LARS): + rng = np.random.RandomState(0) + X_64 = rng.rand(6, 6) + y_64 = rng.rand(6) + + model_64 = LARS().fit(X_64, y_64) + model_32 = LARS().fit(X_64.astype(np.float32), y_64.astype(np.float32)) + + assert_array_almost_equal(model_64.coef_, model_32.coef_) + if hasattr(model_64, "coef_path_"): + assert_array_almost_equal(model_64.coef_path_, model_32.coef_path_) + assert_array_almost_equal(model_64.intercept_, model_32.intercept_) From ccd8841ced174dd3a6073e249e45b0689cf053f8 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Thu, 27 May 2021 18:58:25 +0900 Subject: [PATCH 07/18] Use has_coef_path for parametrize test for explicitly represent the model'coef_path should be tested or nor --- .../linear_model/tests/test_least_angle.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 1ba7aa280dbd0..f0ac8a15d4836 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -779,11 +779,14 @@ def test_copy_X_with_auto_gram(): assert_allclose(X, X_before) -@pytest.mark.parametrize("LARS", (Lars, LassoLars, LassoLarsIC)) +@pytest.mark.parametrize("LARS, has_coef_path", ((Lars, True), + (LassoLars, True), + (LassoLarsIC, False))) @pytest.mark.parametrize("x_data_type, y_data_type, expected_type", ( (np.float32, np.float32, np.float32), (np.float64, np.float64, np.float64))) -def test_lars_dtype_match(LARS, x_data_type, y_data_type, expected_type): +def test_lars_dtype_match(LARS, has_coef_path, + x_data_type, y_data_type, expected_type): rng = np.random.RandomState(0) X = rng.rand(6, 6).astype(x_data_type) y = rng.rand(6).astype(y_data_type) @@ -791,15 +794,15 @@ def test_lars_dtype_match(LARS, x_data_type, y_data_type, expected_type): model = LARS() model.fit(X, y) assert model.coef_.dtype == expected_type - if hasattr(model, "coef_path_"): - # coef_path_ can be list of array - for coef in model.coef_path_: - assert coef.dtype == expected_type + if has_coef_path: + assert model.coef_path_.dtype == expected_type assert model.intercept_.dtype == expected_type -@pytest.mark.parametrize("LARS", (Lars, LassoLars, LassoLarsIC)) -def test_lars_numeric_consistency(LARS): +@pytest.mark.parametrize("LARS, has_coef_path", ((Lars, True), + (LassoLars, True), + (LassoLarsIC, False))) +def test_lars_numeric_consistency(LARS, has_coef_path): rng = np.random.RandomState(0) X_64 = rng.rand(6, 6) y_64 = rng.rand(6) @@ -808,6 +811,6 @@ def test_lars_numeric_consistency(LARS): model_32 = LARS().fit(X_64.astype(np.float32), y_64.astype(np.float32)) assert_array_almost_equal(model_64.coef_, model_32.coef_) - if hasattr(model_64, "coef_path_"): + if has_coef_path: assert_array_almost_equal(model_64.coef_path_, model_32.coef_path_) assert_array_almost_equal(model_64.intercept_, model_32.intercept_) From 71ee583f36fe4d56ffed3e2d8a360a91122f1017 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Fri, 28 May 2021 10:36:25 +0900 Subject: [PATCH 08/18] Add model to be tested and add args to avoid warnings --- .../linear_model/tests/test_least_angle.py | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index f0ac8a15d4836..604a0ebebc2cc 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -14,7 +14,7 @@ from sklearn import linear_model, datasets from sklearn.linear_model._least_angle import _lars_path_residues from sklearn.linear_model import LassoLarsIC, lars_path -from sklearn.linear_model import Lars, LassoLars +from sklearn.linear_model import Lars, LassoLars, LarsCV, LassoLarsCV # TODO: use another dataset that has multiple drops diabetes = datasets.load_diabetes() @@ -779,19 +779,23 @@ def test_copy_X_with_auto_gram(): assert_allclose(X, X_before) -@pytest.mark.parametrize("LARS, has_coef_path", ((Lars, True), - (LassoLars, True), - (LassoLarsIC, False))) +@pytest.mark.parametrize("LARS, has_coef_path, args", + ((Lars, True, {}), + (LassoLars, True, {}), + (LassoLarsIC, False, {}), + (LarsCV, True, {}), + # max_iter=5 is for avoiding ConvergenceWarning + (LassoLarsCV, True, {"max_iter": 5}))) @pytest.mark.parametrize("x_data_type, y_data_type, expected_type", ( (np.float32, np.float32, np.float32), (np.float64, np.float64, np.float64))) -def test_lars_dtype_match(LARS, has_coef_path, +def test_lars_dtype_match(LARS, has_coef_path, args, x_data_type, y_data_type, expected_type): rng = np.random.RandomState(0) X = rng.rand(6, 6).astype(x_data_type) y = rng.rand(6).astype(y_data_type) - model = LARS() + model = LARS(**args) model.fit(X, y) assert model.coef_.dtype == expected_type if has_coef_path: @@ -799,16 +803,21 @@ def test_lars_dtype_match(LARS, has_coef_path, assert model.intercept_.dtype == expected_type -@pytest.mark.parametrize("LARS, has_coef_path", ((Lars, True), - (LassoLars, True), - (LassoLarsIC, False))) -def test_lars_numeric_consistency(LARS, has_coef_path): +@pytest.mark.parametrize("LARS, has_coef_path, args", + ((Lars, True, {}), + (LassoLars, True, {}), + (LassoLarsIC, False, {}), + (LarsCV, True, {}), + # max_iter=5 is for avoiding ConvergenceWarning + (LassoLarsCV, True, {"max_iter": 5}))) +def test_lars_numeric_consistency(LARS, has_coef_path, args): rng = np.random.RandomState(0) X_64 = rng.rand(6, 6) y_64 = rng.rand(6) - model_64 = LARS().fit(X_64, y_64) - model_32 = LARS().fit(X_64.astype(np.float32), y_64.astype(np.float32)) + model_64 = LARS(**args).fit(X_64, y_64) + model_32 = LARS(**args).fit(X_64.astype(np.float32), + y_64.astype(np.float32)) assert_array_almost_equal(model_64.coef_, model_32.coef_) if has_coef_path: From b897381fa48fc0843682d465650e9b32583687db Mon Sep 17 00:00:00 2001 From: takoika <> Date: Fri, 28 May 2021 17:24:34 +0900 Subject: [PATCH 09/18] Use asser_allclose and set absolute torellance --- sklearn/linear_model/tests/test_least_angle.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 604a0ebebc2cc..7ff5187aa834a 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -811,6 +811,8 @@ def test_lars_dtype_match(LARS, has_coef_path, args, # max_iter=5 is for avoiding ConvergenceWarning (LassoLarsCV, True, {"max_iter": 5}))) def test_lars_numeric_consistency(LARS, has_coef_path, args): + atol = 1e-6 + rng = np.random.RandomState(0) X_64 = rng.rand(6, 6) y_64 = rng.rand(6) @@ -819,7 +821,7 @@ def test_lars_numeric_consistency(LARS, has_coef_path, args): model_32 = LARS(**args).fit(X_64.astype(np.float32), y_64.astype(np.float32)) - assert_array_almost_equal(model_64.coef_, model_32.coef_) + assert_allclose(model_64.coef_, model_32.coef_, atol=atol) if has_coef_path: - assert_array_almost_equal(model_64.coef_path_, model_32.coef_path_) - assert_array_almost_equal(model_64.intercept_, model_32.intercept_) + assert_allclose(model_64.coef_path_, model_32.coef_path_, atol=atol) + assert_allclose(model_64.intercept_, model_32.intercept_, atol=atol) From f7e1bbde125a7091d9b98fc5704b48c2c190444d Mon Sep 17 00:00:00 2001 From: takoika <> Date: Fri, 28 May 2021 17:49:54 +0900 Subject: [PATCH 10/18] Relax torellance in order to pass test --- sklearn/linear_model/tests/test_least_angle.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 7ff5187aa834a..35bf3738f0d2c 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -811,7 +811,8 @@ def test_lars_dtype_match(LARS, has_coef_path, args, # max_iter=5 is for avoiding ConvergenceWarning (LassoLarsCV, True, {"max_iter": 5}))) def test_lars_numeric_consistency(LARS, has_coef_path, args): - atol = 1e-6 + rtol = 1e-5 + atol = 1e-5 rng = np.random.RandomState(0) X_64 = rng.rand(6, 6) @@ -821,7 +822,9 @@ def test_lars_numeric_consistency(LARS, has_coef_path, args): model_32 = LARS(**args).fit(X_64.astype(np.float32), y_64.astype(np.float32)) - assert_allclose(model_64.coef_, model_32.coef_, atol=atol) + assert_allclose(model_64.coef_, model_32.coef_, rtol=rtol, atol=atol) if has_coef_path: - assert_allclose(model_64.coef_path_, model_32.coef_path_, atol=atol) - assert_allclose(model_64.intercept_, model_32.intercept_, atol=atol) + assert_allclose(model_64.coef_path_, model_32.coef_path_, + rtol=rtol, atol=atol) + assert_allclose(model_64.intercept_, model_32.intercept_, + rtol=rtol, atol=atol) From e02dfa4757e0117c866fcdaacf37cd69b702d9f4 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Sat, 29 May 2021 10:49:54 +0900 Subject: [PATCH 11/18] Add comments of test aim --- sklearn/linear_model/tests/test_least_angle.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 35bf3738f0d2c..4bab464890d14 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -791,6 +791,7 @@ def test_copy_X_with_auto_gram(): (np.float64, np.float64, np.float64))) def test_lars_dtype_match(LARS, has_coef_path, args, x_data_type, y_data_type, expected_type): + # The test ensures that the fit method preserves input dtype rng = np.random.RandomState(0) X = rng.rand(6, 6).astype(x_data_type) y = rng.rand(6).astype(y_data_type) @@ -811,6 +812,8 @@ def test_lars_dtype_match(LARS, has_coef_path, args, # max_iter=5 is for avoiding ConvergenceWarning (LassoLarsCV, True, {"max_iter": 5}))) def test_lars_numeric_consistency(LARS, has_coef_path, args): + # The test ensures numerical consistency between trained coefficients + # of float32 and float64. rtol = 1e-5 atol = 1e-5 From ebb7c441248b3c45c7605f97c45ec1586d18225f Mon Sep 17 00:00:00 2001 From: takoika <> Date: Sat, 29 May 2021 10:53:17 +0900 Subject: [PATCH 12/18] Remove an unnecessary variable --- sklearn/linear_model/tests/test_least_angle.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 4bab464890d14..45e76b9917e02 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -786,15 +786,15 @@ def test_copy_X_with_auto_gram(): (LarsCV, True, {}), # max_iter=5 is for avoiding ConvergenceWarning (LassoLarsCV, True, {"max_iter": 5}))) -@pytest.mark.parametrize("x_data_type, y_data_type, expected_type", ( - (np.float32, np.float32, np.float32), - (np.float64, np.float64, np.float64))) +@pytest.mark.parametrize("data_type, expected_type", ( + (np.float32, np.float32), + (np.float64, np.float64))) def test_lars_dtype_match(LARS, has_coef_path, args, - x_data_type, y_data_type, expected_type): + data_type, expected_type): # The test ensures that the fit method preserves input dtype rng = np.random.RandomState(0) - X = rng.rand(6, 6).astype(x_data_type) - y = rng.rand(6).astype(y_data_type) + X = rng.rand(6, 6).astype(data_type) + y = rng.rand(6).astype(data_type) model = LARS(**args) model.fit(X, y) From b25243c4ceb423352ec33cb659e2fd2c67e88423 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Sat, 29 May 2021 13:49:44 +0900 Subject: [PATCH 13/18] Use consistent dtype as returned type among X, y, Xy and Gram --- sklearn/linear_model/_least_angle.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index 2762efc299bfd..688335ee2d173 100644 --- a/sklearn/linear_model/_least_angle.py +++ b/sklearn/linear_model/_least_angle.py @@ -476,12 +476,15 @@ def _lars_path_solver( max_features = min(max_iter, n_features) - return_dtype = np.float64 - for input_array in (X, y, Xy, Gram): - if input_array is not None: - return_dtype = input_array.dtype - break + dtypes = set(a.dtype for a in (X, y, Xy, Gram) if a is not None) + if len(dtypes) == 1: + # use the precision level of input data if it is consistent + return_dtype = next(iter(dtypes)) + else: + # fallback to double precision otherwise + return_dtype = np.float64 + print(dtypes, return_dtype) if return_path: coefs = np.zeros((max_features + 1, n_features), dtype=return_dtype) alphas = np.zeros(max_features + 1, dtype=return_dtype) From d50bf478a05792b0dc6af8f61289f5f25f737c77 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Sat, 29 May 2021 13:50:22 +0900 Subject: [PATCH 14/18] Add change log --- doc/whats_new/v1.0.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/whats_new/v1.0.rst b/doc/whats_new/v1.0.rst index 29a4bce98ecb0..c056d24bc9b64 100644 --- a/doc/whats_new/v1.0.rst +++ b/doc/whats_new/v1.0.rst @@ -339,6 +339,10 @@ Changelog is now faster. This is especially noticeable on large sparse input. :pr:`19734` by :user:`Fred Robinson `. +- |Enhancement| `fit` method preserves dtype for numpy.float32 in + :class:`Lars`, :class:`LassoLars`, :class:`LassoLars`, :class:`LarsCV` and :class:`LassoLarsCV`. + :pr:`20155` by :user:`Takeshi Oura `. + :mod:`sklearn.manifold` ....................... From 3d088f11bffced6a662cf2fa58eb4bf1df88a7b4 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Sat, 29 May 2021 14:40:16 +0900 Subject: [PATCH 15/18] Use one parameter --- sklearn/linear_model/tests/test_least_angle.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index 45e76b9917e02..656b7e3fef718 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -786,22 +786,19 @@ def test_copy_X_with_auto_gram(): (LarsCV, True, {}), # max_iter=5 is for avoiding ConvergenceWarning (LassoLarsCV, True, {"max_iter": 5}))) -@pytest.mark.parametrize("data_type, expected_type", ( - (np.float32, np.float32), - (np.float64, np.float64))) -def test_lars_dtype_match(LARS, has_coef_path, args, - data_type, expected_type): +@pytest.mark.parametrize("dtype", (np.float32, np.float64)) +def test_lars_dtype_match(LARS, has_coef_path, args, dtype): # The test ensures that the fit method preserves input dtype rng = np.random.RandomState(0) - X = rng.rand(6, 6).astype(data_type) - y = rng.rand(6).astype(data_type) + X = rng.rand(6, 6).astype(dtype) + y = rng.rand(6).astype(dtype) model = LARS(**args) model.fit(X, y) - assert model.coef_.dtype == expected_type + assert model.coef_.dtype == dtype if has_coef_path: - assert model.coef_path_.dtype == expected_type - assert model.intercept_.dtype == expected_type + assert model.coef_path_.dtype == dtype + assert model.intercept_.dtype == dtype @pytest.mark.parametrize("LARS, has_coef_path, args", From f150fd2dba641aeade131e224bf877df5f4a29c9 Mon Sep 17 00:00:00 2001 From: takoika <> Date: Sat, 29 May 2021 15:01:34 +0900 Subject: [PATCH 16/18] Remove unnecessary print --- sklearn/linear_model/_least_angle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index 688335ee2d173..3485344b99e02 100644 --- a/sklearn/linear_model/_least_angle.py +++ b/sklearn/linear_model/_least_angle.py @@ -484,7 +484,6 @@ def _lars_path_solver( # fallback to double precision otherwise return_dtype = np.float64 - print(dtypes, return_dtype) if return_path: coefs = np.zeros((max_features + 1, n_features), dtype=return_dtype) alphas = np.zeros(max_features + 1, dtype=return_dtype) From c1672a93928e75ca307d8bd5ddab58d35337ca9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20du=20Boisberranger?= <34657725+jeremiedbb@users.noreply.github.com> Date: Mon, 31 May 2021 11:49:22 +0200 Subject: [PATCH 17/18] Update doc/whats_new/v1.0.rst --- doc/whats_new/v1.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/whats_new/v1.0.rst b/doc/whats_new/v1.0.rst index c056d24bc9b64..1c90599968c4e 100644 --- a/doc/whats_new/v1.0.rst +++ b/doc/whats_new/v1.0.rst @@ -340,8 +340,8 @@ Changelog :pr:`19734` by :user:`Fred Robinson `. - |Enhancement| `fit` method preserves dtype for numpy.float32 in - :class:`Lars`, :class:`LassoLars`, :class:`LassoLars`, :class:`LarsCV` and :class:`LassoLarsCV`. - :pr:`20155` by :user:`Takeshi Oura `. + :class:`Lars`, :class:`LassoLars`, :class:`LassoLars`, :class:`LarsCV` and + :class:`LassoLarsCV`. :pr:`20155` by :user:`Takeshi Oura `. :mod:`sklearn.manifold` ....................... From e0bdf8875d1bcb7921afd3c0c523d4dc79990a89 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Mon, 31 May 2021 15:56:35 +0200 Subject: [PATCH 18/18] trigger ci