MCPcopy Index your code
hub / github.com/patrickloeber/pytorchTutorial / gradient

Function gradient

05_1_gradientdescent_manually.py:24–25  ·  view source on GitHub ↗
(x, y, y_pred)

Source from the content-addressed store, hash-verified

22# J = MSE = 1/N * (w*x - y)**2
23# dJ/dw = 1/N * 2x(w*x - y)
24def gradient(x, y, y_pred):
25 return np.mean(2*x*(y_pred - y))
26
27print(f'Prediction before training: f(5) = {forward(5):.3f}')
28

Calls

no outgoing calls

Tested by

no test coverage detected