Skip to content
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

Support alpha=0 in Ridge #6236

Merged
merged 2 commits into from
Jan 24, 2025
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: 3 additions & 4 deletions python/cuml/cuml/linear_model/ridge.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
# Copyright (c) 2019-2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -241,9 +241,8 @@ class Ridge(UniversalBase,
self.intercept_value = 0.0

def _check_alpha(self, alpha):
if alpha <= 0.0:
msg = "alpha value has to be positive"
raise TypeError(msg.format(alpha))
if alpha < 0.0:
raise ValueError(f"alpha must be non-negative, got {alpha}")

def _get_algorithm_int(self, algorithm):
if self.solver not in ['svd', 'eig', 'cd']:
Expand Down
11 changes: 11 additions & 0 deletions python/cuml/cuml/tests/test_linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ def test_ridge_regression_model(datatype, algorithm, nrows, column_info):
)


def test_ridge_and_least_squares_equal_when_alpha_is_0():
X, y = make_regression(n_samples=5, n_features=4, random_state=0)

ridge = cuRidge(alpha=0.0, fit_intercept=False)
ols = cuLinearRegression(fit_intercept=False)

ridge.fit(X, y)
ols.fit(X, y)
assert array_equal(ridge.coef_, ols.coef_)


@pytest.mark.parametrize("datatype", [np.float32, np.float64])
@pytest.mark.parametrize("algorithm", ["eig", "svd"])
@pytest.mark.parametrize(
Expand Down
Loading