Hello! Welcome to the first lesson of our course. We're kicking off the "Mathematical Foundations for Machine Learning" module, which will equip you with the essential mathematical tools needed to understand why and how machine learning models work.
Today, we'll focus on one of the most fundamental concepts in calculus: the derivative. Our goal is to explain the intuition of a derivative as a rate of change and see how it's used to find the minimum or maximum points of functions. This is not just an abstract math exercise; it's the core mechanism behind training many machine learning models. By the end of this lesson, you'll understand the principle behind a process called optimization, which is how a model "learns" from data.
Let's begin by building from a concept you're likely already familiar with: the slope of a line.
From Slope to Instantaneous Change
You know that the slope of a straight line measures its steepness—how much the y value changes for a given change in the x value (often called "rise over run"). For a straight line, this rate of change is constant. But what about a curve, where the steepness is continuously changing? How can we talk about the "slope" at a single point on a curve?
This is the central question that derivatives answer. The derivative of a function at a specific point gives us the instantaneous rate of change at that very point. Geometrically, this is the slope of a straight line that just touches the curve at that point without crossing it—the tangent line.
To build this intuition visually, let's watch the first part of the following video. It does an excellent job of starting with the basic idea of slope and extending it to curves.
Intro to Derivatives | Calculus for Machine Learning
This video, 'Intro to Derivatives' from the 'Calculus for Machine Learning' series by Kylie Ying, will help you visualize the transition from the slope of a line to the slope of a curve.
Please watch the sections explaining the slope of a line (00:37 - 04:21) and how a derivative is the slope of the tangent line to a curve (08:44 - 10:49). Focus on the visual argument for how we define slope at a single point on a non-linear function.
A Physical Analogy: Position, Velocity, and Acceleration
Given your engineering background, a physical analogy might make the idea of a derivative as a rate of change even more concrete. Think about a moving car:
- Its position can be described by a function of time, let's say .
- Its velocity is the rate of change of its position with respect to time. This is the first derivative of the position function, .
- Its acceleration is the rate of change of its velocity. This is the first derivative of the velocity function, which also makes it the second derivative of the position function, .
This article provides an excellent walkthrough of this exact example.
Let's read the first part of the article 'Applications of Derivatives' from MachineLearningMastery.com. It uses the car example to firmly ground the concept of derivatives in a physical context.
Read the section titled 'Applications of Derivatives in Real-Life'. Pay close attention to how the graphs of position, velocity, and acceleration relate to one another. Notice how the velocity graph's value at any time t corresponds to the slope of the position graph at that same time t.
This relationship is key: the derivative function's value at any point tells you the slope, or rate of change, of the original function at that point.
Finding the "Best": How Derivatives Power Optimization
Now for the crucial link to machine learning. Why is finding the rate of change so important?
In many machine learning tasks, we define a loss function (also called a cost or error function). This function measures how "bad" our model's predictions are compared to the actual data. A high loss means bad predictions; a low loss means good predictions. The goal of training is to find the model parameters that make the loss as small as possible—that is, to find the minimum of the loss function.
Imagine the loss function as a landscape of hills and valleys. We want to find the bottom of the lowest valley.

So, how do we find these low points? Think about what's special about the very bottom of a valley (a minimum) or the very top of a hill (a maximum). At these exact points, the ground is momentarily flat. The slope is zero.
This is the fundamental insight: To find the minima or maxima of a function, we can look for the points where its derivative is equal to zero.
The final part of the video you watched earlier explains this application in a machine learning context.
Intro to Derivatives | Calculus for Machine Learning
Let's return to the 'Intro to Derivatives' video to see how setting the derivative to zero is used for optimization in machine learning.
Please watch the segment from 23:03 to 28:10. This part directly connects the concept of a zero derivative to finding the maximum of a 'reward function' or the minimum of a 'loss function'.
The Process: Finding Critical Points
Let's formalize this process, often called the First Derivative Test.
- Define the function you want to minimize or maximize.
- Find its derivative, . To do this practically, we use differentiation rules. The most common one is the power rule, which states that if , then its derivative is .
- Find the critical points by setting the derivative to zero, , and solving for .
- Analyze the critical points. A critical point can be a minimum, a maximum, or neither (like a flat plateau, known as a saddle point). To tell the difference, we check the sign of the derivative on either side of the critical point:
- If the derivative (slope) changes from negative to positive, the function goes from decreasing to increasing. This is a local minimum (a valley).
- If the derivative (slope) changes from positive to negative, the function goes from increasing to decreasing. This is a local maximum (a hill).
This article provides a clear, step-by-step worked example of this process.
Mastering Derivatives for Machine Learning
The article 'Mastering Derivatives for Machine Learning' on Towards AI provides a great breakdown of the First Derivative Test with a clear example.
Read the section 'The First Derivative Test' and follow the 'Working Example' for the function f(X) = 2X³ - 3X² - 12X. This will solidify your understanding of the step-by-step procedure.
Test your understanding!
Let's say a simple loss function for a model is given by , where is a model parameter we can adjust. We want to find the value of that minimizes the loss .
Using the First Derivative Test:
- Find the derivative .
- Set the derivative to zero and solve for the critical point .
- Determine if this point is a minimum.
Show answer
-
Find the derivative: Using the power rule on each term, the derivative of is . (The derivative of a constant like 10 is 0).
-
Find the critical point: Set the derivative to zero:
Solving for , we get , so .
-
Determine if it's a minimum: Let's check the sign of the derivative around .
- For a value less than 3 (e.g., ), , which is negative. The function is decreasing.
- For a value greater than 3 (e.g., ), , which is positive. The function is increasing.
Since the slope changes from negative to positive at , this point is a local minimum. We have found the parameter value that minimizes our loss function.
Conclusion
Congratulations on completing your first lesson! You've taken a significant first step into the mathematical engine that drives machine learning.
Here are the key takeaways:
- A derivative measures the instantaneous rate of change of a function, which is visually represented as the slope of the tangent line at a point.
- In machine learning, we aim to minimize a loss function to find the best model parameters. This process is called optimization.
- We can find potential minimum or maximum points (called critical points) by finding where the function's derivative is equal to zero.
- The First Derivative Test helps us confirm if a critical point is a minimum or maximum by checking the sign of the derivative on either side of it.
In this lesson, we focused on functions with a single variable. However, real-world machine learning models have thousands, millions, or even billions of parameters! In our next lesson, we will explore how the concept of a derivative extends to functions with many variables. This will lead us to the idea of the gradient, a crucial tool for optimizing the complex models you'll encounter in AI.