AI Hints
Statistics & Math for ML · Lesson 91 of 138

Slopes and Rates

How fast it changes.

⏱ 2 min read▶ Video at 1:47:50🎓 Free
Watch this lesson in the Statistics & Math for ML courseWatch on YouTube ↗Full Statistics & Math for ML course

Machine learning models learn by asking one question over and over. If I nudge this weight a little, does the error go up or down, and by how much? That's a question about rates of change. And calculus is the maths of change.

Slopes and Rates
From the video: Slopes and Rates
  • Nudge a weight
  • Does the error go up or down?
  • Calculus: the maths of change

Slope of a line

For a straight line, the rate of change is its slope. Rise over run. How much Y changes, divided by how much X changes. A slope of two means Y goes up two for every one step in X. A negative slope means Y goes down. And a slope of zero means a flat line.

keyvalue
Sloperise ÷ run
2up 2 per step
−1down 1 per step
0flat

Average rate of change

A car's distance, in metres, after T seconds is T squared. That's a curve, not a line, so the speed keeps changing. We can compute the average speed between two times. Run it. Between one and three seconds, four metres per second. Between three and five, eight. The car is speeding up.

rate.pypython
def distance(t):
    return t ** 2

def average_rate(f, a, b):
    return (f(b) - f(a)) / (b - a)

print("1s to 3s:", average_rate(distance, 1, 3), "m/s")
print("3s to 5s:", average_rate(distance, 3, 5), "m/s")
Output
1s to 3s: 4.0 m/s
3s to 5s: 8.0 m/s

Summary

Slope is rise over run, and the average rate of change is the slope between two points. Curves have changing slopes. Next, the slope at a single point, the derivative.

Key takeaways
  • rise / run
  • Average rate between points
  • Curves keep changing
Next up: Derivatives — slope at a point