[MMD]
ML Calculus Chapter 1: Derivatives and Key Differentiation Rules
Training a machine learning model is ultimately about minimizing a loss function. The mathematical tool that makes this minimization possible is the derivative. In this post, we'll build intuition for what a derivative means, then work through the differentiation rules for the most important functions.
This post is based on Week 1 of DeepLearning.AI's Mathematics for Machine Learning and Data Science — Calculus.
What You'll Learn#
- The intuition behind the derivative — instantaneous rate of change and the slope of a tangent line
- The relationship between slope, maxima, and minima
- Differentiation rules for constant, linear, polynomial, exponential, logarithmic, and trigonometric functions
- Conditions for non-differentiability
- The four core differentiation properties: scalar multiplication, sum, product, and chain rules
Why Do We Need Derivatives in Machine Learning?#
Training a machine learning model is an optimization problem.
- Regression: find the line that best explains the data points
- Classification: find the decision boundary that best separates the data
In both cases, we start from an arbitrary line and gradually tweak it toward the best fit. This process is called optimization, and derivatives tell us which direction to move and by how much.
What Is a Derivative? — Instantaneous Rate of Change#
Think of a car's speedometer. You can easily calculate the average speed over a full trip.
But how do you find the speed at a specific instant? You shrink the time interval down to zero.
That is exactly the derivative — the instantaneous rate of change of a function.
Example: Average speed between and seconds
Narrowing to to seconds gives an approximation of the instantaneous speed at seconds.
Key analogy: distance = function , speed = derivative
Tangent Lines and Derivatives#
The instantaneous rate of change is equal to the slope of the tangent line at a point on the curve.
A tangent line touches the curve at exactly one point without crossing through it.
Slope, Maxima, and Minima#
Where do a function's maximum and minimum values occur?
Core principle: A function's maximum or minimum occurs at a point where the derivative equals zero (slope = 0).
| Derivative sign | Meaning |
|---|---|
| Function is increasing | |
| Slope is zero — candidate for extremum (max/min) | |
| Function is decreasing |
In practice: The point where the loss function's derivative equals zero corresponds to the model's optimal parameters. Gradient descent moves toward that point step by step.
Derivative Notation#
There are several common ways to write a derivative.
| Notation | Meaning |
|---|---|
| Lagrange notation | |
| Leibniz notation | |
| Newton notation (typically used for time derivatives) |
Derivatives of Common Functions#
Constant Function#
A constant never changes, so its rate of change is zero.
Linear Function#
The slope is constant everywhere, so the derivative equals at every point. The constant term has no effect on the rate of change.
Quadratic Function#
Intuitive derivation:
Higher-Degree Polynomials (Power Rule)#
Rule: Bring the exponent down as a coefficient, then reduce the exponent by one.
| Function | Derivative |
|---|---|
Derivatives of Inverse Functions#
An inverse function undoes what the original function did.
The derivative of an inverse function is the reciprocal of the original function's derivative.
Derivatives of Trigonometric Functions#
Intuition: As approaches zero, the hypotenuse of the triangle converges to , and working through the algebra yields the trig differentiation formulas.
Euler's Number and the Derivative of Exponential Functions#
What Is ?#
Using compound interest as an analogy:
As grows larger, the expression converges to .
Derivative of #
is the only function that is its own derivative — differentiation leaves it unchanged.
In practice: The derivative of the sigmoid function is central to backpropagation in deep learning.
Derivative of the Logarithmic Function#
Why: is the inverse of , so by the inverse function rule, its derivative is .
When a Derivative Does Not Exist#
Not every function is differentiable at every point.
| Case | Example | Reason |
|---|---|---|
| Cusp | at | Left derivative ≠ right derivative |
| Jump discontinuity | Step function | Function is discontinuous at that point |
| Vertical tangent | at | Slope = (division by zero) |
Functions like these are called non-differentiable functions.
In practice: The ReLU activation is non-differentiable at , but in practice the network uses a subgradient approximation — treating the derivative as either 0 or 1 — to keep training working.
The Four Core Differentiation Properties#
1. Scalar Multiplication Rule#
Multiplying a function by a constant multiplies its derivative by the same constant.
2. Sum Rule#
The derivative of a sum equals the sum of the derivatives.
Intuition: A child running on a moving train — their speed relative to the ground equals the train's speed plus the child's speed.
3. Product Rule#
Example:
4. Chain Rule#
The differentiation rule for composite functions.
Intuition: If you know how altitude affects temperature and how altitude changes over time:
Example:
In practice: Deep learning's backpropagation algorithm is essentially the repeated application of the chain rule to compute the gradient at each layer.
Summary of Differentiation Formulas#
| Function | Derivative |
|---|---|
| (constant) | |
| Rule | Formula |
|---|---|
| Scalar multiplication | |
| Sum rule | |
| Product rule | |
| Chain rule |
Quiz#
Q1. Differentiate the following function.
Show answer
Apply the sum rule, scalar multiplication rule, and power rule:
Q2. Differentiate .
Show answer
Product rule:
Q3. Differentiate .
Show answer
Chain rule: ,
Q4. Which of the following functions is NOT differentiable at ?
Show answer
Option 2:
At , the left-hand derivative is and the right-hand derivative is — they differ, so the derivative does not exist. (This is a cusp.)
Q5. Differentiate .
Show answer
Apply the chain rule twice: ,
The next post will cover optimization, partial derivatives, gradients, and gradient descent.
// Related Posts
Probability & Statistics in Practice: Inference Problems from the ML Trenches
From probability fundamentals and Bayes' theorem to distributions, MLE/MAP, confidence intervals, and hypothesis testing — a collection of practice problems grounded in real ML and data analysis scenarios.
Probability & Statistics Coding Assignments: Building ML Statistical Tools in Python
Bayesian updates, distribution simulation, CLT verification, MLE/MAP implementation, confidence intervals, hypothesis testing, and a full A/B test pipeline — implementing probability & statistics chapters 1–4 in code.
ML Probability & Statistics Chapter 4: Confidence Intervals and Hypothesis Testing
A complete guide to confidence intervals, the t-distribution, hypothesis testing fundamentals (null/alternative hypotheses, p-values, rejection regions, statistical power), various t-tests, and A/B testing.