Skip to content

statistics.correlation() is inaccurate for tiny inputs #161259

Open

Description

@vmphase

Bug report

Originally discovered by @Broyojo, statistics.correlation() returns a wrong result when the sums of squared deviations are tiny, even though correlation is scale-invariant:

>>> import statistics
>>> statistics.correlation([1e-100, 2e-100, 3e-100], [1e-62, 2e-62, 3e-62])
0.8997827589086393

The expected result is 1.0. Normalizing both inputs by max(abs(...)) first gives 1.0.
P.S. The same problem applies to any nonzero product that is subnormal.

CPython versions tested on:

3.14, 3.15, 3.13

Operating systems tested on:

Windows, Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 3, 2026
  2. added 4 commits that reference this issue on Nov 3, 2026
  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions