Hello! Welcome to the fourth lesson in our module on the mathematical foundations of machine learning.
In the last lesson, we explored eigenvalues and eigenvectors, which reveal the intrinsic directions of a linear transformation—the vectors that are only scaled, not rotated. This gave us insight into the stability of systems, like deep neural networks.
Today, we shift our focus from the directions of transformations to the rates of change within functions. We'll explore one of the most fundamental concepts in calculus: the derivative. Understanding derivatives is absolutely essential for machine learning, as they are the primary tool we use to train and optimize our models.
This lesson addresses the learning outcome: Compute derivatives and partial derivatives; interpret as rates of change. By the end of this lesson, you will be able to:
- Explain the derivative as an instantaneous rate of change, or the slope of a function at a single point.
- Calculate the derivative of simple functions using the power rule.
- Compute partial derivatives for functions with multiple variables.
- Understand how these concepts are used to measure the impact of inputs on a function's output.
1. The Intuition: What is an "Instantaneous" Rate of Change?
We often talk about rates of change in everyday life—the speed of a car, the growth of a company's revenue. These are usually calculated over a period of time. But what if we want to know the rate of change at a single instant? This question presents a fascinating paradox. Change requires two points in time to measure, but an instant is just one point.
Calculus provides an elegant solution to this paradox. Let's build our intuition with a video from 3Blue1Brown, which is renowned for its excellent visual explanations.
The paradox of the derivative | Chapter 2, Essence of calculus
This video, 'The paradox of the derivative', uses the example of a moving car to build the concept of a derivative from the ground up, resolving the paradox of instantaneous change.
Watch from the beginning to 09:44. Pay close attention to how the idea of velocity (rate of change of distance) is first approximated over a small time interval (dt) and then formalized by asking what that approximation approaches as the interval becomes infinitesimally small.
As the video masterfully explains, the derivative is not calculated with a time interval of zero. Instead, it's the limit that the rate of change approaches as the interval dt (or more generally, Δx) shrinks towards zero.
Visually, this corresponds to finding the slope of the line tangent to the function's graph at a specific point.

So, a derivative answers the question: "How much does my function's output change for a tiny nudge in its input?" It represents the instantaneous rate of change.
2. Calculating Derivatives: From Limits to Rules
While the limit definition is the theoretical foundation, calculating it every time would be tedious. Fortunately, mathematicians have derived simple rules for finding derivatives. For polynomial functions, the most important one is the power rule.
The Power Rule: For any function of the form , its derivative is .
For example:
- If , its derivative is .
- If , its derivative is .
- If , we keep the constant and apply the rule: .
The following video provides a practical guide to applying this rule and introduces the next key concept for our lesson.
Derivatives | Deep Learning Tutorial 9 (Tensorflow Tutorial, Keras & Python)
This video from codebasics offers a straightforward explanation of how to calculate derivatives using basic rules and then connects this concept directly to machine learning.
Watch from 00:23 to 05:12. This will cover the difference between slope for linear vs. non-linear functions and demonstrate how to apply the power rule to find the derivative.
You can even write a simple Python function to approximate a derivative numerically, which directly implements the "rise-over-run" idea from the 3Blue1Brown video.
Calculus — ML Glossary documentation
This reading from the 'ML Cheatsheet' reinforces the geometric definition and shows how the limit definition is used to derive the rule for f(x) = x². It also provides a simple Python code example.
Read the sections 'Introduction', 'Derivatives', 'Geometric definition', 'Taking the derivative', and 'Step-by-step'. Notice how the formal derivation for f(x) = x² arrives at the same 2x result as the power rule.
3. Partial Derivatives: Handling Multiple Inputs
Machine learning models rarely have just one input. A model predicting house prices might depend on square footage, number of bedrooms, age of the house, and so on. A loss function depends on millions of model weights. How do we find the rate of change then?
We use partial derivatives. A partial derivative measures the rate of change with respect to one variable, while treating all other variables as if they were constants.
The key insight is simple: to find the partial derivative of with respect to , you just pretend is a number (like 5 or ) and apply the normal differentiation rules.
Let's look at an example: .
- Partial derivative with respect to x (treating as a constant):
- Partial derivative with respect to y (treating as a constant):
The symbol (called "del") is used to signify a partial derivative.
Let's return to the codebasics video to see this explained in the context of a practical example.
Derivatives | Deep Learning Tutorial 9 (Tensorflow Tutorial, Keras & Python)
Here, the video explains partial derivatives and, crucially, frames them in the context of a machine learning problem: how does a change in one feature (like number of bedrooms) affect the predicted house price?
Watch from 05:12 to 10:51. Focus on the core idea: when taking a partial derivative with respect to one variable, you treat all others as constants. Understand the connection to ML: we use partial derivatives to see how changing a single weight in a neural network affects the overall error.
The geometric intuition for partial derivatives is powerful. If a function of two variables creates a 3D surface (like a landscape), taking a partial derivative is like taking a 2D "slice" through that landscape and finding the slope of the resulting curve.

For a more detailed explanation of the notation and intuition, the following reading is excellent.
Partial Derivatives & Gradients for Machine Learning
This article from TensorTonic focuses specifically on partial derivatives, offering a clear definition, worked examples, and a great geometric intuition of 'slicing the surface'.
Read the sections from 'Introduction' through 'Geometric Intuition'. The analogies of 'slicing the surface' and walking 'East-West' vs. 'North-South' are very helpful for building intuition.
4. The Gradient: A Vector of Partial Derivatives
When we have a function with multiple variables, we can compute the partial derivative for each one. If we collect all of these partial derivatives into a vector, we get the gradient, denoted by .
For a function , the gradient is:
The gradient vector is arguably the single most important concept in modern machine learning. Why? Because it points in the direction of the steepest ascent of the function. If you want to increase a function's value as quickly as possible (e.g., maximize profit), you should move in the direction of the gradient. If you want to decrease it as quickly as possible (e.g., minimize error), you move in the opposite direction. This is the core idea behind gradient descent, the optimization algorithm that powers the training of most neural networks.
Conclusion
In this lesson, we laid the groundwork for understanding how machine learning models learn. We moved from the abstract concept of an "instantaneous rate of change" to the practical tools of derivatives and partial derivatives.
Key Takeaways:
- Derivative: The derivative of a function at a point measures its instantaneous rate of change, which is geometrically interpreted as the slope of the tangent line at that point.
- Power Rule: A simple rule for calculating derivatives of polynomial functions: the derivative of is .
- Partial Derivative: Measures the rate of change of a multi-variable function with respect to one variable, while holding all others constant. This is crucial for understanding the effect of individual features or weights in a model.
- Gradient: A vector that bundles together all the partial derivatives of a function. It points in the direction of the function's steepest increase.
In our next lesson, we will learn about the chain rule. While the power rule is great for simple functions, machine learning models are complex, nested functions (functions within functions). The chain rule is the key that will unlock our ability to compute gradients for these complex models, a process you will come to know as backpropagation.