8000 [MRG+2] Minor changes in ridge float64 upcasting by massich · Pull Request #9125 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+2] Minor changes in ridge float64 upcasting #9125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sklearn/linear_model/ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,11 @@ def __init__(self, alpha=1.0, fit_intercept=True, normalize=False,

def fit(self, X, y, sample_weight=None):

if self.solver in ['svd', 'sparse_cg', 'cholesky', 'lsqr']:
_dtype = [np.float64, np.float32]
else:
if self.solver in ('sag', 'saga'):
_dtype = np.float64
else:
# all other solvers work at both float precision levels
_dtype = [np.float64, np.float32]

X, y = check_X_y(X, y, ['csr', 'csc', 'coo'], dtype=_dtype,
multi_output=True, y_numeric=True)
Expand Down
16 changes: 9 additions & 7 deletions sklearn/linear_model/tests/test_ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,12 @@ def test_dtype_match():
ridge_64.fit(X_64, y_64)
coef_64 = ridge_64.coef_

# Do all the checks at once, like this is easier to debug
assert_almost_equal(ridge_32.coef_, ridge_64.coef_, decimal=5)

# Do the actual checks at once for easier debug
assert_equal(coef_32.dtype, X_32.dtype)
assert_equal(coef_64.dtype, X_64.dtype)
assert coef_32.dtype == X_32.dtype
assert coef_64.dtype == X_64.dtype
assert ridge_32.predict(X_32).dtype == X_32.dtype
assert ridge_64.predict(X_64).dtype == X_64.dtype
assert_almost_equal(ridge_32.coef_, ridge_64.coef_, decimal=5)


def test_dtype_match_cholesky():
Expand All @@ -844,6 +844,8 @@ def test_dtype_match_cholesky():
coef_64 = ridge_64.coef_

# Do all the checks at once, like this is easier to debug
assert_equal(coef_32.dtype, X_32.dtype)
assert_equal(coef_64.dtype, X_64.dtype)
assert coef_32.dtype == X_32.dtype
assert coef_64.dtype == X_64.dtype
assert ridge_32.predict(X_32).dtype == X_32.dtype
assert ridge_64.predict(X_64).dtype == X_64.dtype
assert_almost_equal(ridge_32.coef_, ridge_64.coef_, decimal=5)
0