Skip to content

Instantly share code, notes, and snippets.

@joaofig
Created October 13, 2018 18:02
Show Gist options
  • Select an option

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

Select an option

Save joaofig/fa8b0b341c887c76a44ae4ee54dbdd57 to your computer and use it in GitHub Desktop.
Calculates the estimated y values for a quadratic function
def calculate_y_hat(self, x, y):
xx, yy = x, y
if torch.is_tensor(x):
xx = x.numpy()
if torch.is_tensor(y):
yy = y.numpy()
coefficients = np.polyfit(xx, yy, 2)
polynomial = np.poly1d(coefficients)
y_hat = polynomial(xx)
return y_hat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment