Repository navigation
ENH: add array API support for contingency_matrix - #34785
Conversation
|
CC: @lucyleeow @virchan @ogrisel @betatim I opened an updated version of the earlier PR. Could you kindly review and merge? |
| def yield_metric_checker_combinations(metric_checkers=array_api_metric_checkers): | ||
| for metric, checkers in metric_checkers.items(): | ||
| for checker in checkers: | ||
| yield metric, checker |
There was a problem hiding this comment.
Nit not directly related to this PR (sorry) - instead of maintaining the array_api_metric_checkers list, what if we used the existing list names e.g. SUPERVISED_METRICS and then just yield the appropriate check? We would iterate over all cluster metrics and just maintain a temp list of metrics that do not yet support array api (during the period where we are in process of adding support)
(similar to what is done in sklearn/metrics/tests/test_common.py)
There was a problem hiding this comment.
I checked this and it seems like the main issue with adding this particular metric to the SUPERVISED_METRICS is that it returns a NumPy array instead of a Python float which all the others do so which would require skipping this from about 5 tests in the file.
There was a problem hiding this comment.
Ah how annoying. What about a new variable SUPERVISED_METRICS_CONTINGENCY that includes contingency_matrix and is used for array API testing?
Not ideal but we do it for classification_report in metrics test_common.py as this outputs a string:
scikit-learn/sklearn/metrics/tests/test_common.py
Lines 319 to 321 in 53302ff
There was a problem hiding this comment.
I guess a separate mapping SUPERVISED_METRICS_CONTINGENCY that just contains contingency_matrix for now seems reasonable.
virchan
left a comment
There was a problem hiding this comment.
LGTM. The Intel CI passes as well. Thanks, @OmarManzoor!
Also, +1 on #34785 (comment).
lucyleeow
left a comment
There was a problem hiding this comment.
LGTM just 2 comments. I imagine #34785 (comment) would need to be in a different PR because there would need to be a bit of fiddlying, esp as contingency_matrix is currently not in the SUPERVISED_METRICS list and adding it may require fiddling with tests or excluding it from some tests.
| metric, | ||
| array_namespace, | ||
| device, | ||
| dtype_name, # This is used for atol so it needs to be float or None |
There was a problem hiding this comment.
this comment doesn't make sense as we add int above?
There was a problem hiding this comment.
Actually dtype_name is the original float dtype which we pass here. We can't simply pass the loop variable dt_name as that can contain int which doesn't work with atol
There was a problem hiding this comment.
Ah i see the problem is that check_array_api_metric cannot handle ints - but I guess this works fine.
There was a problem hiding this comment.
Yeah the original float works fine. I guess we can merge but the refactoring change you suggested makes sense too. I guess a follow up could work for that to dedicatedly do the refactoring work. Thank you
There was a problem hiding this comment.
Here, I wonder if it makes sense (later) to add int support to _atol_for_type?
There was a problem hiding this comment.
I guess that is something that could be considered. Not sure how much usage it would have though.
Reference Issues/PRs
Supersedes: #29251
What does this implement/fix? Explain your changes.
contingency_matrix