Created
October 20, 2020 22:21
-
-
Save rjurney/1a887b475734c7239fdbfef6ceafb64d to your computer and use it in GitHub Desktop.
Implementations of R^2 Score
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def r2_score(y_true, y_pred): | |
"""Implements the Coeffecient of Determination, R^2 or R-squared""" | |
SS_res = kb.sum(kb.square(y_true - y_pred)) | |
SS_tot = kb.sum(kb.square(y_true - kb.mean(y_true))) | |
return (1 - SS_res / (SS_tot + kb.epsilon())) | |
def inverse_r2_score(y_true, y_pred): | |
"""Implements the inverse Coeffecient of Determination, R^2 or R-squared""" | |
SS_res = kb.sum(kb.square(y_true - y_pred)) | |
SS_tot = kb.sum(kb.square(y_true - kb.mean(y_true))) | |
return 1 / (1 - SS_res / (SS_tot + kb.epsilon())) | |
def negative_r2_score(y_true, y_pred): | |
"""Implements the negative Coeffecient of Determination, R^2 or R-squared""" | |
SS_res = kb.sum(kb.square(y_true - y_pred)) | |
SS_tot = kb.sum(kb.square(y_true - kb.mean(y_true))) | |
return -1 * (1 - SS_res / (SS_tot + kb.epsilon())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment