Equations of Lines
A line's equation names its starting height and its rate of climb, so two numbers predict every point the line will ever pass through.
Why Does This Exist?
Straight lines are the atoms of modeling: linear regression fits one, decision stumps split on them, gradients follow them locally, and every curve is a line under a microscope. Writing a line as an equation turns a picture into a predictor: plug in any , get the , with no drawing.
Two numbers do it all, which is the quiet miracle. The slope sets the rate, the intercept sets the start, and together they fix infinitely many points. This page teaches the slope-intercept form and how to read it. Systems of lines continue in linear systems and least squares; the coordinate setting is coordinate geometry.
The one idea you need first
A rate compares change in one quantity to change in another: miles per hour, dollars per item. A line's slope is exactly a rate, change in per unit of , held constant along the whole line. Constant rate is what makes it straight.
Think of It Like This
A staircase with an entry floor
Picture a staircase in a building. The entry floor is the intercept: where you start before climbing. The step shape is the slope: each step forward rises a fixed amount. Tell someone both and they know every landing without walking: entry floor plus steps times step-height.
A line is a staircase with tiny smooth steps. Steeper steps reach higher faster but overshoot sooner when extended; shallow steps take longer to get anywhere. The analogy stops at straightness: real staircases turn, while the equation climbs one rate forever.
How It Actually Works
The slope-intercept form with slope and y-intercept is:
In plain words: is rise over run between any two points on the line; is the value where the line crosses the vertical axis (); is the input and the output. Positive climbs left to right, negative falls, is flat. Given two points, from distance and midpoint, then .
Vertical lines refuse this form (their slope divides by zero) and use instead. That exception is the only crack in an otherwise universal tool.
Worked example
Build the line through and :
- Slope: .
- Intercept: at , , so .
- Equation: .
Predict and check: at , ; at , . Each step across climbs exactly 2, and extending to predicts . The three plotted points , , sit evenly spaced on the drawn line, confirming one rate throughout.
Code
Fit the rate and the start from two points, then predict.
import numpy as np
x = np.array([0.0, 3.0])y = np.array([1.0, 7.0])m = (y[1] - y[0]) / (x[1] - x[0]) # rise over runb = y[0] - m * x[0] # height at x = 0print(m, b) # -> 2.0 1.0print(m * 10 + b) # -> 21.0Slope 2.0, intercept 1.0, prediction 21.0 at : the equation earns its keep in three lines.
Watch Out For
Extrapolating the line past the data
The equation happily predicts , but the straight trend almost never survives that far: saturation, regime change, or physical limits bend reality while the line marches on. Training data spanned 0 to 3; the prediction at 10 is a guess wearing math's clothes.
Interpolate freely, extrapolate with a stated reason. If a forecast far outside the data range drives a decision, demand a mechanism, not just a fitted slope.
Forcing vertical structure into y = mx + b
A near-vertical decision boundary fit in slope form gets an enormous where tiny noise swings wildly. The form assumes is a function of , one per , which vertical structure violates.
Detect it by exploding past the problem's natural scale, then switch to the general form or parametrize the line by direction instead.
The Quick Version
- : slope is the rate, intercept is the value at zero.
- Through and the line is , hitting 7 at .
- Two points fix a line: slope from the gaps, intercept from either point.
- Positive slopes climb, negative fall, zero is flat, vertical needs .
- Interpolate with confidence; extrapolate only with a mechanism behind it.
- Watch for exploding slopes that signal near-vertical structure.