-
Notifications
You must be signed in to change notification settings - Fork 615
Open
Description
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])
Metadata
Metadata
Assignees
Labels
No labels