I had some fun tonight writing a linear regression algorithm from scratch in Kotlin. To execute gradient descent, I spent an hour figuring out partial derivatives, which basically is a Calculus derivative targeting one variable at a time, assuming all the other variables are constant.
The partial derivatives can then be used to measure slope of the error, and when that slope approaches 0 you hit a local minimum and found an optimal line. I'll post a video on this later.
[Source Code is on GitHub](
https://gist.github.com/thomasnield/fbe2e2205233388577e6abe6f5bbe897)
[Desmos Graph](
https://www.desmos.com/calculator/ntomwigo6k)