Matthews correlation coefficient gives wrong results for single-class result

### 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

```shell
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.")
```

COMMENT:
First, I thought that we could quickly fix the problem you pointed out with something like:
```python
if all(y_true == y_pred):
    return 1
```
But this problem is more general: MCC and Pearson Correlation (as far as I understand) are not defined if we have a constant array/variable because the standard deviation would be zero. This would lead to a division by zero, as we can see from the [Wikipedia definition below](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient):
![image](https://user-images.githubusercontent.com/55899543/210184465-897b3915-7510-4e25-99ef-052b67d1798d.png)

This happens in other implementations of the Pearson correlation coefficient as well:
```python
import numpy as np
from scipy.stats import pearsonr

y_true = 10*[1] + [0]
y_pred = 10*[1] + [1]

np.corrcoef(y_true, y_pred)
>>>> RuntimeWarning: invalid value encountered in divide c /= stddev[None, :]
>>>> array([[ 1., nan],
       [nan, nan]])

pearsonr(y_true, y_pred)
>>>> ConstantInputWarning: An input array is constant; the correlation coefficient is not defined.
>>>> PearsonRResult(statistic=nan, pvalue=nan)

# Note that matthews_corrcoef = 0 here for the same reason:
matthews_corrcoef(y_true, y_pred)
>>>> 0
```

But I agree with you that this can be misleading. Especially if you are doing some `sklearn.model_selection.BaseSearchCV` for hyperparameter optimization, you will get some 0 scores (that actually doesn't mean anything). Comparing them with another model with a -0.1 MCC score is not straightforward. Which one is better?
<details>

Indeed MCC is one "available by default" metric in the `sklearn.model_selection.BaseSearchCV` classes.
```python
from sklearn.metrics import get_scorer_names
'matthews_corrcoef' in get_scorer_names()
>>>> True
```

Also, the example I'm talking about is not extreme, as y_pred = 0 for all instances can happen when you have a highly imbalanced problem (and you are using default `.predict`, i.e., with 0.5 as the threshold, which is the case for `sklearn.model_selection.BaseSearchCV`).
</details>

Anyway, I don't see a straightforward change to fix this issue, as using Pearson Correlation doesn't do the trick as far as I can see. Is there another way of using it that you were thinking @dsphilli1?

(Also, you can check #19977 for historical decision/context.)

Labels: Bug, module:metrics