ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Calculus Essentials for Machine Learning
Chapter 1: Introduction: Why Calculus Matters in Machine Learning
Functions and Models in ML
The Concept of Optimization in ML
Measuring Change: The Role of Derivatives
Calculus as a Tool for Understanding Algorithms
Quiz for Chapter 1
Chapter 2: Single-Variable Calculus: Derivatives and Optimization
Understanding Limits: The Foundation
Defining the Derivative
Common Differentiation Rules
Higher-Order Derivatives
Finding Minima and Maxima using Derivatives
Application: Simple Cost Function Optimization
Hands-on Practical: Calculating Derivatives with Python
Quiz for Chapter 2
Chapter 3: Multivariable Calculus: Gradients and Direction
Functions of Multiple Variables
Partial Derivatives
The Gradient Vector
Directional Derivatives
The Hessian Matrix
Multivariable Optimization Concepts
Hands-on Practical: Computing Gradients with NumPy
Quiz for Chapter 3
Chapter 4: Gradient Descent Algorithms
The Intuition Behind Gradient Descent
The Gradient Descent Algorithm Steps
The Learning Rate Parameter
Batch Gradient Descent
Stochastic Gradient Descent (SGD)
Mini-batch Gradient Descent
Challenges: Local Minima and Saddle Points
Hands-on Practical: Implementing Simple Gradient Descent
Quiz for Chapter 4
Chapter 5: The Chain Rule and Backpropagation
Revisiting the Chain Rule for Single Variables
The Chain Rule for Multivariable Functions
Introduction to Neural Networks as Composite Functions
Backpropagation: Applying the Chain Rule
Calculating Gradients for Weights and Biases
Computational Graphs
Hands-on Practical: Manual Backpropagation Example
Quiz for Chapter 5

Measuring Change: The Role of Derivatives

Machine learning models are often represented as functions. The goal is typically to optimize these functions, finding the inputs (parameters) that yield the best possible output (e.g., lowest error). How are these 'best' parameters systematically found? Simply trying random values is inefficient, especially when models have millions of parameters. A method is needed to determine which direction to adjust the parameters.

Imagine you're standing on a hillside in thick fog and want to get to the bottom (the lowest point). You can't see the whole area, but you can feel the slope of the ground right where you are. If the ground slopes down to your left, you'd take a step left. If it slopes down in front of you, you'd step forward. This "slope" tells you the direction of steepest descent.

In mathematics, the tool for measuring the instantaneous slope or rate of change of a function at a specific point is the derivative.

The Derivative: Measuring Instantaneous Change

Think about a function f(x)f(x)f(x) that represents our model's cost (how bad it is) based on a single parameter xxx. We want to find the value of xxx that minimizes f(x)f(x)f(x). The derivative of f(x)f(x)f(x) with respect to xxx, often written as f′(x)f'(x)f′(x) or dfdx\frac{df}{dx}dxdf​, tells us how much the output f(x)f(x)f(x) changes for a tiny change in the input xxx.

Geometrically, the derivative f′(a)f'(a)f′(a) gives the slope of the line tangent to the graph of y=f(x)y = f(x)y=f(x) at the point where x=ax = ax=a.

  • Positive Derivative (f′(a)>0f'(a) > 0f′(a)>0): The function is increasing at x=ax=ax=a. If we increase xxx slightly, f(x)f(x)f(x) will increase. The tangent line slopes upwards.
  • Negative Derivative (f′(a)<0f'(a) < 0f′(a)<0): The function is decreasing at x=ax=ax=a. If we increase xxx slightly, f(x)f(x)f(x) will decrease. The tangent line slopes downwards.
  • Zero Derivative (f′(a)=0f'(a) = 0f′(a)=0): The function is momentarily flat at x=ax=ax=a. This could be a minimum point, a maximum point, or a saddle point (a flat spot that isn't a minimum or maximum). The tangent line is horizontal.

For example, the function f(x)=x2−2x+3f(x) = x^2 - 2x + 3f(x)=x2−2x+3. Let's visualize its slope at different points:

The plot shows the function f(x)=x2−2x+3f(x) = x^2 - 2x + 3f(x)=x2−2x+3. At x=−1x=-1x=−1, the tangent line (red dashed) slopes downward (negative derivative), indicating the function is decreasing. At x=1x=1x=1, the tangent line (yellow dashed) is horizontal (zero derivative), indicating a potential minimum. At x=3x=3x=3, the tangent line (green dashed) slopes upward (positive derivative), indicating the function is increasing.

Why Derivatives Matter for Optimization

This concept is directly applicable to optimizing machine learning models. Our "cost function" is the function we want to minimize. The model's parameters are the inputs to this function.

If we calculate the derivative of the cost function with respect to a specific parameter:

  1. A negative derivative tells us that increasing the parameter will decrease the cost. So, to minimize the cost, we should increase the parameter.
  2. A positive derivative tells us that increasing the parameter will increase the cost. To minimize the cost, we should decrease the parameter.
  3. A zero derivative suggests we might be at a minimum (or maximum/saddle point) with respect to that parameter.

By calculating derivatives for all parameters, we know the "direction of steepest ascent" for the cost. To minimize the cost, we simply take a small step in the opposite direction. This is the core idea behind gradient descent, one of the most common optimization algorithms in machine learning, which we will explore in detail later.

For now, the important takeaway is that derivatives provide a quantitative measure of how a function's output changes with its input. This measure is essential for navigating the complex details of a model's cost function and iteratively adjusting parameters to find the optimal values. In the following chapters, we'll formalize the definition of the derivative, learn how to calculate derivatives for various functions, and extend these ideas to functions with many inputs (parameters), which is the typical scenario in machine learning.

  • Mathematics for Machine Learning, Marc Peter Deisenroth, A. Aldo Faisal, and Cheng Soon Ong, 2020 (Cambridge University Press) DOI: 10.1017/9781108679930 - This book connects essential mathematical concepts, including derivatives and optimization, directly to their use in machine learning algorithms.
  • Deep Learning, Ian Goodfellow, Yoshua Bengio, and Aaron Courville, 2016 (MIT Press) - The book's chapter on numerical computation introduces optimization algorithms like gradient descent and explains how derivatives are applied in training machine learning models.
  • 18.01SC Single Variable Calculus, Massachusetts Institute of Technology (MIT OpenCourseWare), 2010 (MIT OpenCourseWare) - Provides comprehensive video lectures and materials for learning single-variable calculus, offering a strong foundation in derivatives and their properties.

© 2026 ApX Machine Learning