Calculus for ML: Derivatives Part – 01

Calculus for ML: Derivatives Part – 01

Do you know calculus plays an important role in ML? I am going to show you how derivates performs a vital role to make the most accurate model for you. Let’s start !!

First let’s have a look at some derivatives.

*Calculating a slope: *

slope = rise/run
= change in x axis/change in y axis
= ∆x/∆y


Here, the slope is going to be –
slope = ∆x/∆t
= x(15) – x(10) / t(15) – t(10)
= 202-122 / 15-10
= 16 m/s

Now, I ask you a question. At t = 12.5. what is the velocity? If not the exact velocity, find me a good estimate.
Let’s find out the slope,

slope = ∆x/∆t
= (177-155)/(13-12) = 15 m/s

But this is just a roughly value. We still don’t know the exact estimate value of v at t=12.5s. To find this, we need finer and finer intervals. The more finer, the more accurate answer it is, and this is where the importance of derivate comes.

1. Derivatives and Tangents
A tangent is a line that touches a curve at only one point. The line points out the slope of the tangent to that point. A derivative of a function gives you the gradient of a tangent at a certain point on a curve.


Look, how the intervals are coming closer as we are getting smaller to smaller. This gets so close that we can’t even find the difference. These are called instantaneous rate of change aka the derivatives.

2. Derivative of a line


slope = ∆y/∆x
= rise/run
= a(x+∆x)+b-(ax+b) / x+∆x-x
= a∆x/∆x = a
So, the derivative of the eq(ax+b) is the slope a.

3. Derivative of Quadratic Function :

slope = ∆f/∆x = {f(x+∆x)^2 – f(x)^2} / ∆x
Between (1,1) and (1.5, 2.25) –
∆x = 2-1 = 1
[∆f = 4-1 = 3 ; y2 – y1]
∆f = (x+∆x)^2 – (x)^2
=> (1+1)^2 – 1 => 4-1 = 3
so, slope = 3

Between (1,1) and (1.5, 2.25)-
∆x = 1.5 – 1 = 0.5
∆f = (x+∆x)^2 – (x)^2
= (1+0.5)^2 – 1 = 1.25
slope = 1.25/0.5 = 2.5

Even smaller: (1,1) and (1.25, 1.56) –
∆x = 1.25-1 = 0.25
∆f = (x+∆x)^2 – (x)^2 = (1+0,25)^2 – 1 = 0.56
slope = 0.56 / 0.25 = 2.25

Again, d/dx(f) = {f(x+∆x)^2 – f(x)^2} / ∆x
= (x^2 + 2x∆x + ∆x^2)/ ∆x = 2x + ∆x

So, f(x) = x^2 => f'(x) = 2x

4. Derivative of Cubic function

slope = ∆f/∆x = {f(x+∆x)^3 – f(x)}/∆x
If you apply the cubic formula, it will end at 3x^2 + 3x∆x + ∆x^2.
As, ∆x -> 0, so, f'(y) = 3x^2

5. Derivative of 1/x

Here, i am going to make it short –
slope = ∆f/∆x = {f(x+∆x)^(-1) – f(x)}/∆x

f(x) = x^(-1)
=> f'(x) = -x^(2)

I hope you noticed that i basically followed the rule nx^(n-1)

Leave a Reply

Your email address will not be published. Required fields are marked *