Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Concerns about the Pearson's Correlation Metrics computed by tensorflow_addons #2878

Description

@sungmingyen

Hello, I am using tensorflow_addons during the model.fit() process to print out the R2 and Pearson metrics.

In theory, the square of the Pearson coefficient should be similar to the R2 value. However, the values computed by this package do not match. Even after ruling out the possibility of a reversed order mistake (as shown in the attached image) — and even if reversed, there is no square relationship — I would like to ask what might be causing this issue.

Image

Additionally, I calculated R2 using another method, and it is consistent with the R2 computed by tensorflow_addons, but the Pearson metric is inconsistent. I initially suspect that tensorflow_addons might have an issue in how it calculates Pearson's correlation.

Here is the code:

import tensorflow as tf
from tensorflow import keras
import tensorflow_addons as tfa 

saved_model_folder = "m_20250317-1915"
best_model = "ep233-loss124.6872-vloss207.1709"
model = keras.models.load_model(f'trn_models/{saved_model_folder}/{best_model}',compile=False)

# compile again
metrics=[tfa.metrics.RSquare(name= 'r2'), tfa.metrics.PearsonsCorrelation(name="pearson") ]
# if needed,  tfa.metrics.KendallsTauC(name="kendall_tauC") can also be used.
model.compile(optimizer='adam', loss='mse', metrics=metrics)

# model evaluate
results = model.evaluate(tst, verbose=0)
print("="*60)
print(f"{saved_model_folder} - Best Model Applied on Testing Data".center(60))
print("="*60)
print(f"Best Epochs: {best_model}")

print("MSE:", results[0])
print("R2:", results[1])
print("Pearsons's Correlation Coefficient:", results[2])

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions