-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FIX _check_reg_targets with Array API and multioutput argument #29143
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e74881d
fix
Tialo ba4f351
remove f
Tialo d68b63b
Add test
lesteve a1248ce
Merge branch 'main' of https://github.com/scikit-learn/scikit-learn i…
lesteve 83d5f7d
Fix after merge
lesteve 54088bd
simplify test
lesteve 94aa797
Add changelog
lesteve 1d7baf2
Update sklearn/metrics/tests/test_common.py
lesteve 2535a13
Further simplification
lesteve 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
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 |
---|---|---|
|
@@ -1762,6 +1762,10 @@ def check_array_api_metric( | |
metric_kwargs["sample_weight"], device=device | ||
) | ||
|
||
multioutput = metric_kwargs.get("multioutput") | ||
if isinstance(multioutput, np.ndarray): | ||
metric_kwargs["multioutput"] = xp.asarray(multioutput, device=device) | ||
|
||
with config_context(array_api_dispatch=True): | ||
metric_xp = metric(a_xp, b_xp, **metric_kwargs) | ||
|
||
|
@@ -1869,8 +1873,8 @@ def check_array_api_regression_metric(metric, array_namespace, device, dtype_nam | |
def check_array_api_regression_metric_multioutput( | ||
metric, array_namespace, device, dtype_name | ||
): | ||
y_true_np = np.array([[1, 3], [1, 2]], dtype=dtype_name) | ||
y_pred_np = np.array([[1, 4], [1, 1]], dtype=dtype_name) | ||
y_true_np = np.array([[1, 3, 2], [1, 2, 2]], dtype=dtype_name) | ||
y_pred_np = np.array([[1, 4, 4], [1, 1, 1]], dtype=dtype_name) | ||
|
||
check_array_api_metric( | ||
metric, | ||
|
@@ -1894,12 +1898,25 @@ def check_array_api_regression_metric_multioutput( | |
sample_weight=sample_weight, | ||
) | ||
|
||
check_array_api_metric( | ||
metric, | ||
array_namespace, | ||
device, | ||
dtype_name, | ||
a_np=y_true_np, | ||
b_np=y_pred_np, | ||
multioutput=np.array([0.1, 0.3, 0.7], dtype=dtype_name), | ||
) | ||
|
||
def check_array_api_multioutput_regression_metric( | ||
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. Before, there was |
||
metric, array_namespace, device, dtype_name | ||
): | ||
metric = partial(metric, multioutput="raw_values") | ||
check_array_api_regression_metric(metric, array_namespace, device, dtype_name) | ||
check_array_api_metric( | ||
metric, | ||
array_namespace, | ||
device, | ||
dtype_name, | ||
a_np=y_true_np, | ||
b_np=y_pred_np, | ||
multioutput="raw_values", | ||
) | ||
|
||
|
||
def check_array_api_metric_pairwise(metric, array_namespace, device, dtype_name): | ||
|
@@ -1949,11 +1966,11 @@ def check_array_api_metric_pairwise(metric, array_namespace, device, dtype_name) | |
cosine_similarity: [check_array_api_metric_pairwise], | ||
mean_absolute_error: [ | ||
check_array_api_regression_metric, | ||
check_array_api_multioutput_regression_metric, | ||
check_array_api_regression_metric_multioutput, | ||
], | ||
mean_squared_error: [ | ||
check_array_api_regression_metric, | ||
check_array_api_multioutput_regression_metric, | ||
check_array_api_regression_metric_multioutput, | ||
], | ||
d2_tweedie_score: [ | ||
check_array_api_regression_metric, | ||
|
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.
I added more values to avoid having n_rows == n_columns