Skip to content

Matthews correlation coefficient gives wrong results for single-class result #25258

@dsphilli1

Description

@dsphilli1

Describe the bug

for a single class input, (ie perfect correlation) MCC returns 0, when it should return 1.

since MCC is a special case of pearson correlation, it should fall back to pearson when appropriate

Steps/Code to Reproduce

from sklearn.metrics import matthews_corrcoef
y_true = [1, 1, 1, 1]
y_pred = [1, 1, 1, 1]
matthews_corrcoef(y_true, y_pred)
Out [9]: 0.0

Expected Results

output should be 1

Actual Results

output is 0

Versions

import sklearn; sklearn.show_versions()

System:
    python: 3.9.12 (main, Apr  5 2022, 01:53:17)  [Clang 12.0.0 ]
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
          pip: 22.3.1
   setuptools: 65.5.1
      sklearn: 1.0.2
        numpy: 1.22.3
        scipy: 1.9.3
       Cython: 0.29.32
       pandas: 1.5.2
   matplotlib: 3.6.2
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True
/Users/phild1/opt/anaconda3/lib/python3.9/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions