Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SungMY-Jeff opened this issue Mar 18, 2025 · 0 comments

Comments

@SungMY-Jeff
Copy link

SungMY-Jeff commented Mar 18, 2025

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])
@SungMY-Jeff SungMY-Jeff changed the title Investigating Inconsistencies in R2 and Pearson Metrics Calculated by TensorFlow Addons Investigating Inconsistencies in Pearson Metrics Calculated by TensorFlow Addons Mar 18, 2025
@SungMY-Jeff SungMY-Jeff changed the title Investigating Inconsistencies in Pearson Metrics Calculated by TensorFlow Addons Concerns about the Pearson's Correlation Metrics computed by tensorflow_addons Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant