Repository navigation
Description
Warning
This is a request for comment (RFC) and is not open for contribution. Great if you are interested to contribute to scikit-learn 🙏. Please have a look at our contributing doc and in particular the section New Contributors.
Some metric functions upcast to max float type (via _max_precision_float_dtype) during computation; for example confusion_matrix_at_thresholds does this because it uses cumulative_sum, which suffers from precision degradation due to error accumulation. (Aside, note that we return arrays at max dtype, and do not convert back to input dtype).
Some estimators also upcast during computation, e.g., RidgeCV, but we return attribute arrays to input array dtype (AFAICT) so the 'output' dtype is matches input dtype.
If the user is using a device that only supports float 32 (i.e. MPS), it is possible that they suffer from precision problems when using these metrics/estimators. Currently, we inform users of this by adding a "(see Note on device support for float64)" beside that estimator/metric in our docs.
This also affects the mixed array namespace/device inputs situation (wrt metric functions see #31274 and #32755 and wrt fit and predict see #33076). If we are moving arrays to a device where only float32 is supported, precision may be affected for the above estimators/metrics.
How do we remember to document this and make it clear to people reading the code that a downcast is occurring? Options discussed during the last array API meeting (not mutually exclusive):
- Use existing estimator tag system to tag estimators affected
- this excludes metrics. Note that although we do check that the output of metrics with different array namespace inputs matches that of numpy, this will not always pick up on precision problems as it is data dependent
- Add a
dtypekwarg tomove_to- this would make it clearer in the code that a potential downcast was occurring (see discussion TST Add common test for mixed array API inputs for metrics #32755 (comment))- though this would make it more difficult to use the same
move_tofunction for both array conversion and 'converting' an estimator, see: Raise if fit and predict use different array API namespaces or devices (continued) #33076 (comment)
- though this would make it more difficult to use the same
@ogrisel @betatim @lesteve I may have missed something or mis-understood something, please update if I have.
Activity