You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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])
The text was updated successfully, but these errors were encountered:
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
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
Uh oh!
There was an error while loading. Please reload this page.
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.
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:
The text was updated successfully, but these errors were encountered: