def pearson_correlation(y_true, y_pred, axis=-1):
    """Computes the Pearson coefficient between labels and predictions.

    Formula:

    ```python
    loss = mean(l2norm(y_true - mean(y_true) * l2norm(y_pred - mean(y_pred)))
    ```

    Args:
        y_true: Tensor of true targets.
        y_pred: Tensor of predicted targets.
        axis: Axis along which to determine similarity. Defaults to `-1`.

    Returns:
        Pearson Correlation Coefficient tensor.

    Example:

    >>> y_true = [[0, 1, 0.5], [1, 1, 0.2]]
    >>> y_pred = [[0.1, 0.9, 0.5], [1, 0.9, 0.2]]
    >>> loss = keras.losses.concordance_correlation(
    ...     y_true, y_pred, axis=-1
    ... ).numpy()
    [1.         0.99339927]
    """
    y_pred = ops.convert_to_tensor(y_pred)
    y_true = ops.convert_to_tensor(y_true, dtype=y_pred.dtype)
    y_true, y_pred = squeeze_or_expand_to_same_rank(y_true, y_pred)

    y_true_norm = y_true - ops.mean(y_true, axis=axis, keepdims=True)
    y_pred_norm = y_pred - ops.mean(y_pred, axis=axis, keepdims=True)

    y_true_norm = y_true_norm / ops.std(y_true_norm, axis=axis, keepdims=True)
    y_pred_norm = y_pred_norm / ops.std(y_pred_norm, axis=axis, keepdims=True)

    return ops.mean(y_true_norm * y_pred_norm, axis=axis)
Computes the Pearson coefficient between labels and predictions.

    Formula:

    ```python
    loss = mean(l2norm(y_true - mean(y_true) * l2norm(y_pred - mean(y_pred)))
    ```

    Args:
        y_true: Tensor of true targets.
        y_pred: Tensor of predicted targets.
        axis: Axis along which to determine similarity. Defaults to `-1`.

    Returns:
        Pearson Correlation Coefficient tensor.

    Example:

    >>> y_true = [[0, 1, 0.5], [1, 1, 0.2]]
    >>> y_pred = [[0.1, 0.9, 0.5], [1, 0.9, 0.2]]
    >>> loss = keras.losses.concordance_correlation(
    ...     y_true, y_pred, axis=-1
    ... ).numpy()
    [1.         0.99339927]
    
keras/src/metrics/correlation_metrics.py