TST Make test_ridge_regression_dtype_stability less random
@@ -1124,16 +1124,18 @@ def test_dtype_match_cholesky():
@pytest.mark.parametrize(
'solver', ['svd', 'cholesky', 'lsqr', 'sparse_cg', 'sag', 'saga'])
-def test_ridge_regression_dtype_stability(solver):
- random_state = np.random.RandomState(0)
+@pytest.mark.parametrize('seed', range(1))
+def test_ridge_regression_dtype_stability(solver, seed):
+ random_state = np.random.RandomState(seed)
n_samples, n_features = 6, 5
X = random_state.randn(n_samples, n_features)
coef = random_state.randn(n_features)
- y = np.dot(X, coef) + 0.01 * rng.randn(n_samples)
+ y = np.dot(X, coef) + 0.01 * random_state.randn(n_samples)
alpha = 1.0
- rtol = 1e-2 if os.name == 'nt' and _IS_32BIT else 1e-5
-
results = dict()
+ # XXX: Sparse CG seems to be far less numerically stable than the
+ # others, maybe we should not enable float32 for this one.
+ atol = 1e-3 if solver == "sparse_cg" else 1e-5
for current_dtype in (np.float32, np.float64):
results[current_dtype] = ridge_regression(X.astype(current_dtype),
y.astype(current_dtype),
@@ -1148,4 +1150,4 @@ def test_ridge_regression_dtype_stability(solver):
assert results[np.float32].dtype == np.float32
assert results[np.float64].dtype == np.float64
- assert_allclose(results[np.float32], results[np.float64], rtol=rtol)
+ assert_allclose(results[np.float32], results[np.float64], atol=atol)
