MATHEMATICS FOR AI • LESSON 3

Derivatives

A derivative tells us how quickly something changes. In AI, derivatives help us understand how changing a model's parameters affects its predictions and error.

CORE IDEA

A derivative tells us how much an output changes when an input changes.

This idea becomes extremely important in AI because a model needs to know how its parameters should change to reduce its error.

01

What Is a Derivative?

A derivative measures the rate at which one value changes compared with another value.

In simple words:

Derivative = How quickly something is changing

Imagine you are driving a car. Your position changes as time passes.

Time       Position

1 second    10 meters
2 seconds   20 meters
3 seconds   30 meters

Your position is changing as time changes. The derivative tells us the rate of that change.

02

A Simple Real-World Example

Consider the speed of a car.

If a car travels 100 kilometers in 2 hours:

Distance = 100 km
Time     = 2 hours

Average speed = Distance / Time

              = 100 / 2

              = 50 km/h

Speed tells us how quickly distance changes with respect to time.

Distance
    ↓
changes with
    ↓
Time

Rate of change = Speed

This is the basic idea behind a derivative: measuring change.

03

Derivative of a Simple Function

Let's take the function:

f(x) = x²

The derivative of this function is:

f'(x) = 2x

The symbol f'(x) means the derivative of the function.

If:

x = 3

Then:

f'(3) = 2 × 3

      = 6

This means that at x = 3, the function is changing at a rate of 6.

04

What Does the Derivative Actually Tell Us?

Let's use a simple function:

y = x²

Some values are:

x       y

1       1
2       4
3       9
4       16
5       25

Notice that the output does not increase by the same amount every time.

The derivative tells us how quickly the output is changing at a particular point.

Derivative:

f'(x) = 2x

At x = 1 → derivative = 2
At x = 2 → derivative = 4
At x = 3 → derivative = 6
At x = 4 → derivative = 8

As x becomes larger, the function changes more quickly.

05

Positive, Negative, and Zero Derivatives

A derivative can be positive, negative, or zero. This tells us the direction of change.

Positive derivative
        ↓
Value is increasing


Negative derivative
        ↓
Value is decreasing


Zero derivative
        ↓
Value is not changing at that point

Think about walking up and down a hill.

Walking uphill
     ↓
Positive slope


Walking downhill
     ↓
Negative slope


Flat ground
     ↓
Zero slope

This idea of direction becomes very important when an AI model tries to reduce its error.

06

Derivative as a Slope

Another useful way to understand a derivative is as the slope of a function at a particular point.

Large positive slope
        /
       /
      /

Small positive slope
      /
     /
    ───


Negative slope
    \
     \
      \

A steep slope means the value is changing quickly. A flat slope means the value is changing slowly.

Therefore:

Derivative
    =
Rate of Change
    =
Slope at a Point
07

Why Do AI Models Need Derivatives?

This is the most important part for AI.

An AI model contains parameters such as weights. These weights affect the model's predictions.

Input
  ↓
AI Model
  ↓
Prediction
  ↓
Compare with actual answer
  ↓
Loss / Error

Suppose the model makes a prediction that is wrong. We want to change its weights so that the next prediction is better.

But how do we know which direction to change a weight?

Change weight slightly
        ↓
Observe change in error
        ↓
Derivative tells us
how the error changed

This is why derivatives are fundamental to machine learning.

08

Simple AI Example

Imagine an AI model has one weight.

weight = 2

The model produces some prediction, and we calculate its error.

Prediction = 70
Actual     = 100

Error = 30

Now suppose the derivative tells us:

Derivative = -10

The negative value tells the learning algorithm that changing the weight in a particular direction can help reduce the error.

The actual training process is more complicated, but this simple example gives you the correct intuition.

09

Derivative and Learning

AI training can be viewed as repeatedly asking:

"If I change this parameter,
what happens to the error?"

The derivative provides the mathematical answer to this question.

Model Parameter
       ↓
Change parameter slightly
       ↓
Observe effect on Loss
       ↓
Derivative
       ↓
Know which direction to move

This process is repeated many times while the model learns.

10

Derivatives Lead to Gradients

A simple AI model may have many parameters instead of just one.

weight1
weight2
weight3
weight4
weight5
...
weight1000

We need to know how the loss changes with respect to all these parameters.

This leads to the idea of a gradient.

One parameter
      ↓
Derivative


Many parameters
      ↓
Gradients

We will study gradients in the next lesson.

11

Derivatives in the AI Learning Process

Put everything together:

Input Data
    ↓
AI Model
    ↓
Prediction
    ↓
Calculate Loss
    ↓
Calculate Derivative
    ↓
Understand how parameters affect Loss
    ↓
Change Parameters
    ↓
Better Prediction

This is one of the foundations behind how machine learning models learn from their mistakes.

WHAT TO REMEMBER

A derivative tells us how quickly something changes.

In AI, derivatives help us understand how changing model parameters affects the model's error. This information is later used by gradients and gradient descent to improve the model.