Data Science Math 101: Derivatives
Derivatives are an interesting concept and a powerful tool in data science. To understand them, it’s useful to have a basic understanding of functions in math first. Make sure to give it a read and come back again.
Okay, let’s dive right in.
A derivative tells us the slope of a function. In other words, it lets us calculate the rate of change in a function at any given point.
Have a look at the following graph:
The x-axis represents time, while the y-axis represents speed. We could imagine the graph shows the speed of a car with respect to time. The shape of the function tells us that it’s linear. As x grows, y grows at the same rate with respect to x. In fact, we can see that the function we’re dealing with is y = x.
Let’s ignore for a second that we know the definition of the function and say we want to know at what rate y changes (or, how fast the car accelerates) between two points in time.
The way we visualize this is by drawing another line that touches both points. That line is also known as tangent line. As you might have guessed, drawing a tangent line that touches those two points will look exactly like the line we already have.
Coincidence? Not really. It doesn’t matter where we put those two points in our original function, the tangent line will always look the same. In other words, the slope or “steepness” of the function stays the same. Recall that the slope of a line represents the rate of change in y values as the x values change. In this case, for every increase in x by 1, the y value also increases by 1, so the slope is 1/1 = 1.
More generally, we can calculate the slope between two points using the following formula, also known as rise-over-run:
When we plug in the numbers of our example, we see that the slope for y = x is indeed 1:
Let’s do this again but this time with a function that grows exponentially:
This looks much more interesting! This is the graph for the function y = x**2 and its tangent line that touches the curve at x = 4 and y = 6. Again, we can calculate the slope between these two points by plugging our x and y values into the formula:
The slope between the two points is 10.
Now what happens however, if we not only change the distance between the points, but also place the points somewhere else on the curve altogether? The graph below shows the tangent line at x = 0.5 and x = 2.
Notice how the slope of the tangent line has changed. If we do the slope calculation once more, we’ll see that the slope between the two points is 2.5:
As the two points change in distance or move along the curve, the tangent line and its slope will change with respect to those two points as well.
Up next…
We’ve explored how to calculate the slope between two points in a function, but it turns out we can calculate the slope of any single x value of a function as well.
This will be the topic of the next post.







