Franck Binde FR
Franck Binde (Maths for data and AI) Guide 01 · Learning and sharing

The derivative

Understand a rate of change with a drive from Yaoundé to Douala, a shower, a diagram you play with, then a spreadsheet exercise.

  1. 01A drive from Yaoundé to Douala
  2. 02You already do it: the shower
  3. 03The real explanation
  4. 04What it's used for in data and AI
  5. 05The interactive diagram
  6. 06Your turn
  7. 07How an AI computes a derivative
  8. 08The quiz
01The drive

To begin: a drive from Yaoundé to Douala

Imagine you are driving from Yaoundé to Douala. In the passenger seat, a friend writes down your position every hour. At noon, you are at kilometre 40. At 1 pm, at kilometre 120.

40 kmposition at noon
120 kmposition at 1 pm
80 km/haverage speed: 80 km ÷ 1 h

Nothing mysterious here, it's a simple division: the change in distance, divided by the change in time.

But this average hides what really happened. During that hour, you may have slowed down in a traffic jam in Édéa, then sped along a long straight stretch. If your friend writes down your position every ten minutes, they see very different speeds from one moment to the next. If they do it every minute, or every second, they discover your speed more and more precisely, almost at every instant.

This is where the question gets interesting. What does “your speed at this exact instant” mean, since no time passes in an instant? You can't divide by zero. What we do is shrink the interval more and more: an hour, a minute, a second, a thousandth of a second. And we watch which value the speed settles on. That value we are heading towards is the derivative.

Remember: the derivative is the rate of change, measured over an interval that has become infinitely small.

02The shower

You already do it: the shower

You have already used a derivative without knowing it. You are adjusting the temperature of your shower. The water is too hot: you turn the tap a little towards cold. Too cold now: you turn it the other way, but less. Little by little, you find the right temperature.

What exactly did you do? With each move, you ask yourself: if I turn the tap a little, does the temperature go up or down, and how fast? That question, “how does it change when I adjust this setting a little?”, is exactly what a derivative measures. And you correct in the right direction, in small steps, until you get the result you want.

03The explanation

The real explanation

Let's go back to the curve of your position on the road. Pick an instant, then a second instant a little later. Join the two points with a straight line: its slope is your average speed between those two moments.

Now move the second point closer to the first, again and again. The line pivots, and ends up just touching the curve at a single point, like a ruler laid against it. It is called the tangent. Its slope is your speed at that exact instant.

Definition: the derivative of a function at a point is the slope of the tangent to its curve at that point.

04The jobs

What it's used for in data and AI jobs

Artificial intelligence

Imagine a model trying to predict the price of a house. At first, it gets it very wrong. We measure its error with a number: the bigger it is, the more wrong the model is. The model has internal settings, called parameters. It asks itself the same question you do in the shower: if I adjust this setting a little, does my error go up or down, and by how much? The answer is the derivative of the error with respect to the setting.

If the error goes up when the setting increases, the model lowers it. If it goes down, it keeps going that way. It repeats this thousands of times, in small steps. This is gradient descent, and it is literally how a model learns.

Finance

An analyst wants to know how much the price of a financial product changes if the interest rate moves by a tiny amount. That sensitivity is a derivative.

Data science

To fit a line to a cloud of points, we look for the line that minimises the error: we use the derivative to find where that error is lowest.

05The diagram

The interactive diagram

The curve shows the distance travelled over time. Point A is fixed, at t = 2 hours. Slide the slider towards zero to bring point B closer.

1.50 h
time t (hours) distance (km) A B
Line AB Tangent at A
Slope of line AB
Value it is heading towards4

The closer you bring B to A, the more the slope settles on one value. That value is the derivative at A.

06Your turn

Your turn: check it yourself

What you will do: check, with real numbers, that a speed “at an exact instant” exists. You will measure your speed over shorter and shorter intervals, and you will see the result settle on one value. That is exactly what the diagram's slider did, but this time, you do the calculating.

What you need: a spreadsheet (Excel or Google Sheets) and 10 minutes. No complicated formula: a few subtractions and one division.

The story: you are driving, and the distance travelled since the start equals the time squared. After 2 hours, you have covered 4 km. After 3 hours, 9 km. It isn't realistic for a real car, but the numbers stay simple.

Here is what your spreadsheet will show at the end. Now let's build it together.

Time (hours)DistanceAverage speed since t = 2
24starting point
395
2.14.414.1
2.014.04014.01
  1. Set up your table

    Why: to see the numbers side by side.

    In column A, write the times: 2 in A2, 3 in A3. In column B, write the distance: 4 in B2, 9 in B3.

  2. Your average speed over one hour

    Why: it's your first, rough measurement, like the average speed of the Yaoundé-Douala drive.

    In cell C3, type the formula =(B3-B2)/(A3-A2). You get 5. It means: between the 2nd and the 3rd hour, you drove at an average of 5 km/h.

  3. Shrink the interval

    Why: this is the heart of the idea. The shorter the interval, the closer the measurement gets to your speed at the exact instant t = 2.

    Add a row: in A4 write 2.1 and in B4 write 4.41 (that's 2.1 × 2.1). In cell C4, copy the same formula, but with row 4 and row 2: =(B4-B2)/(A4-A2). You get 4.1.

    Do it again with 2.01 (distance 4.0401): you get 4.01.

    If your spreadsheet is set to French, type a comma instead of a point: 2,1 and 4,41.

  4. Look at what happens

    Why: this is the click moment.

    Look at your three results: 5, then 4.1, then 4.01. They get closer to one number, and after a while they barely move. That number is 4. It's your exact speed at t = 2, and it's the derivative at that point. You just found it yourself.

07How pros do it

How pros do it: the derivative computed by PyTorch

Engineers who train artificial intelligence don't compute their derivatives by hand, or in a spreadsheet. They use PyTorch, a free tool for the Python language. It's the most widely used tool in the world for training AI.

Here is your exercise, written the way a professional would write it: the distance equals the time squared, and we want the exact speed at t = 2.

Python · PyTorch
import torch

t = torch.tensor(2.0, requires_grad=True)
distance = t * t
distance.backward()
print(t.grad)
What the screen showstensor(4.)

To run it yourself: copy the code, open Google Colab, paste it and press the play button. You'll need a Google account. Then replace 2.0 with 3.0 and see what changes.

Open Google Colab ↗
  1. import torch

    We open the PyTorch toolbox.

  2. t = torch.tensor(2.0, requires_grad=True)

    We set the time to 2 hours, and ask PyTorch to keep an eye on this number: we'll want to know how the result reacts when it moves.

  3. distance = t * t

    We write the formula: the distance equals the time times the time.

  4. distance.backward()

    The key move. PyTorch computes the derivative on its own. It doesn't bring any points closer: it knows the derivative of each small operation and chains them together. The result is exact on the first try.

  5. print(t.grad)

    We display the derivative. It's called the "gradient", hence the word grad.

The screen shows 4. That's the value the slope was heading towards in the diagram, and the one your spreadsheet was approaching with 5, then 4.1, then 4.01. The word "tensor" around it is simply how PyTorch stores its numbers.

In a real AI, it's the same command, but for billions of settings at once. The model reads all these derivatives, nudges each setting in the right direction, and starts again millions of times.

08The quiz

The quiz: 5 questions

Five questions, four answers each. One of the answers is only there to make you smile.