tf.keras.metrics.pearson_correlation

Computes the Pearson coefficient between labels and predictions.

Formula:

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

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

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]