Skip to content

RFC: dtype downcasting and precision in array API #33366

Open

Description

@lucyleeow

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):

@ogrisel @betatim @lesteve I may have missed something or mis-understood something, please update if I have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions