Skip to content

Instantly share code, notes, and snippets.

@joaofig
Created October 13, 2018 17:56
Show Gist options
  • Select an option

  • Save joaofig/623caef67207cb2ae572c7e899c896c6 to your computer and use it in GitHub Desktop.

Select an option

Save joaofig/623caef67207cb2ae572c7e899c896c6 to your computer and use it in GitHub Desktop.
Calculate the factor of determination
def calculate_determination(self, y, y_hat):
y_np = y.numpy() if torch.is_tensor(y) else y
y_bar = np.sum(y_np) / len(y_np)
ssreg = np.sum((y_hat - y_bar) ** 2)
sstot = np.sum((y_np - y_bar) ** 2)
r2 = ssreg / sstot
return r2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment