Calculus and Gradients
Derivatives, partial derivatives, the chain rule and gradients: what lets a model know which way to adjust its parameters.
Beginner · about 12 hours · difficulty 3/5
Learn first: Linear Algebra for ML
Training is minimizing a loss function. The gradient tells you the direction of steepest increase, so stepping the opposite way decreases the loss. Backpropagation is simply the chain rule applied efficiently.
Concepts
- Derivatives as local slopes; derivatives of common functions (polynomials, exp, log, sigmoid).
- Partial derivatives and the gradient vector for functions of many parameters.
- The chain rule: derivative of a composition. Draw computation graphs to apply it mechanically.
- Jacobians and Hessians: shapes of derivatives for vector outputs and second-order curvature (conceptual level).
- Numerical gradient checking: approximate
(f(x+h) - f(x-h)) / 2hto verify an analytic gradient.
Practical focus
You will rarely derive gradients by hand in practice because autograd does it, but you must understand them to debug vanishing gradients, choose learning rates and read papers. Derive the gradient of mean squared error for linear regression and of log loss for logistic regression once, by hand.
Good enough to move on when you can compute the gradient of a small composed function via a computation graph and confirm it numerically.
Key concepts
- Derivatives of common functions
- Partial derivatives and gradients
- Chain rule and computation graphs
- Jacobians and Hessians
- Numerical gradient checking
Mini project
Derive the MSE gradient for linear regression, implement it in NumPy, verify it with finite differences, and use it to fit a line to synthetic noisy data.
Check yourself
Using the chain rule, what is the derivative of sigmoid(w * x + b) with respect to w?
Free resources
- Essence of Calculus (3Blue1Brown)
- Mathematics for Machine Learning (vector calculus chapter) (Deisenroth, Faisal, Ong)
- Khan Academy: Multivariable calculus (Khan Academy)