This post follows my lecture above, from the core idea of gradient descent to a linear regression model in PyTorch.
Full notebook: https://colab.research.google.com/drive/1vn_ZsqwSp16cI8O7gVltU5sJNSJrXNRW .
A shorter, code-free explanation is on Medium: https://medium.com/@lochanjangidcoder/lecture-on-linear-regression-gradient-descent-from-scratch-by-lochan-jangid-f0d5ba9115f8?sharedUserId=lochanjangidcoder .
Linear regression and gradient descent are two of the core ideas of machine learning. We will build the math first, then the model, using code from my lecture notebook.
Part 1: The core idea of gradient descent
Take a simple equation:
x * 4 = 12
Enter fullscreen mode
Exit fullscreen mode
We know x is 3. Let’s pretend we don’t, and build a system that finds x by itself.
Start with a guess. Say x = 0. The output is 4 * 0 = 0, but the target is 12. The distance between the output and the target is the error , here 12. The target is constant, so the only thing we can change is x.…