-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
FIX array api support for clip
param of MinMaxScaler
#29615
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
Closed
StefanieSenger
wants to merge
14
commits into
scikit-learn:main
from
StefanieSenger:MinMaxScaler.clip
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
55a406c
fix array api support for clip param
StefanieSenger 8e29418
for debugging failing cuda test
StefanieSenger edd4734
for debugging cuda tests
StefanieSenger f3c1993
for debugging cuda tests [ci skip]
StefanieSenger 07fb554
for debugging cuda tests [ci skip]
StefanieSenger 5f05d7e
for debugging cuda tests [ci skip]
StefanieSenger 08fe48f
for debugging cuda tests [ci skip]
StefanieSenger aea8369
for debugging cuda tests [ci skip]
StefanieSenger b9501ca
for debugging cuda tests [ci skip]
StefanieSenger b734f9b
for debugging cuda tests [ci skip]
StefanieSenger ec74f74
for debugging cuda tests [ci skip]
StefanieSenger 22b1010
for debugging cuda tests [ci skip]
StefanieSenger 7416505
for debugging cuda tests [ci skip]
StefanieSenger 553a2e1
changes according to review
StefanieSenger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,7 +9,7 @@ | |||||
import pytest | ||||||
from scipy import sparse, stats | ||||||
|
||||||
from sklearn import datasets | ||||||
from sklearn import config_context, datasets | ||||||
from sklearn.base import clone | ||||||
from sklearn.exceptions import NotFittedError | ||||||
from sklearn.metrics.pairwise import linear_kernel | ||||||
|
@@ -41,6 +41,7 @@ | |||||
yield_namespace_device_dtype_combinations, | ||||||
) | ||||||
from sklearn.utils._testing import ( | ||||||
_array_api_for_tests, | ||||||
_convert_container, | ||||||
assert_allclose, | ||||||
assert_allclose_dense_sparse, | ||||||
|
@@ -2475,14 +2476,19 @@ def test_standard_scaler_sparse_partial_fit_finite_variance(X_2): | |||||
assert np.isfinite(scaler.var_[0]) | ||||||
|
||||||
|
||||||
@pytest.mark.parametrize("feature_range", [(0, 1), (-10, 10)]) | ||||||
def test_minmax_scaler_clip(feature_range): | ||||||
@pytest.mark.parametrize( | ||||||
"array_namespace, device, _", yield_namespace_device_dtype_combinations() | ||||||
) | ||||||
@pytest.mark.parametrize("feature_range", [(0.0, 1.1), (-10.0, 10.0)]) | ||||||
def test_minmax_scaler_clip(feature_range, array_namespace, device, _): | ||||||
# test behaviour of the parameter 'clip' in MinMaxScaler | ||||||
X = iris.data | ||||||
scaler = MinMaxScaler(feature_range=feature_range, clip=True).fit(X) | ||||||
X_min, X_max = np.min(X, axis=0), np.max(X, axis=0) | ||||||
X_test = [np.r_[X_min[:2] - 10, X_max[2:] + 10]] | ||||||
X_transformed = scaler.transform(X_test) | ||||||
xp = _array_api_for_tests(array_namespace, device) | ||||||
X = xp.asarray(iris.data) | ||||||
with config_context(array_api_dispatch=True): | ||||||
scaler = MinMaxScaler(feature_range=feature_range, clip=True).fit(X) 8000 td> | ||||||
X_min, X_max = xp.min(X, axis=0), xp.max(X, axis=0) | ||||||
X_test = xp.asarray([np.r_[X_min[:2] - 10, X_max[2:] + 10]]) | ||||||
X_transformed = scaler.transform(X_test) | ||||||
assert_allclose( | ||||||
X_transformed, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
[[feature_range[0], feature_range[0], feature_range[1], feature_range[1]]], | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put
array_api
in the test name so that it can be picked up by the CUDA CI that only runs tests with "array_api" in their name to avoid spending GPU time running non-array API tests.