# Calculus and Gradients

> Derivatives, partial derivatives, the chain rule and gradients: what lets a model know which way to adjust its parameters. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/calculus-gradients
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-algebra)

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)) / 2h` to 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](https://www.3blue1brown.com/topics/calculus) (3Blue1Brown)
- [Mathematics for Machine Learning (vector calculus chapter)](https://mml-book.github.io/) (Deisenroth, Faisal, Ong)
- [Khan Academy: Multivariable calculus](https://www.khanacademy.org/math/multivariable-calculus) (Khan Academy)

Previous: [Linear Algebra for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-algebra) · Next: [Probability for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/probability)

## More in The Math Behind the Models

- [Linear Algebra for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-algebra)
- [Calculus and Gradients](https://www.internhack.in/roadmaps/tracks/machine-learning/calculus-gradients)
- [Probability for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/probability)
- [Statistics for Data Science](https://www.internhack.in/roadmaps/tracks/machine-learning/statistics)
- [Optimization and Gradient Descent](https://www.internhack.in/roadmaps/tracks/machine-learning/optimization)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
