Index Ai Academy
Foundation · Foundation mathAlgebra

Straight lines: slope and intercept

About 42 minLooking ahead: some prerequisites aren't done yet

Why this matters

A straight line is the simplest way one thing can depend on another: each step across adds the same amount up. Two numbers describe it completely, its slope and its intercept. The first machine learning model you'll ever train, linear regression, is exactly this: the weight is the slope and the bias is the intercept. This lesson is where algebra and models meet. You'll also learn to read a line from a table, from a graph and from its formula.

  • Read y = mx + b: the slope as rise over run, and the intercept as y at x = 0
  • Find the line through two points, and tell when two lines are parallel
  • Work out slope and intercept in Python, print a table of a line and draw its graph
  • See a model's weight as a slope and its bias as an intercept, and predict from a line
Quick check
Have a guess before you start. A straight line goes through (0, 3) and (2, 7). What is y when x = 4?

The math: a constant climb

Purpose. Describe the simplest way one quantity can depend on another.

A straight line has the equation

y=mx+by = mx + b

In plain words: m is the slope, how much y goes up for each step of 1 across. b is the intercept, where the line crosses the y-axis, the value of y when x = 0.

In y = 2x + 3, every step right climbs 2, and the line starts at 3 when x = 0. A negative slope goes downhill: y falls as x grows. A slope of 0 is flat.