0PricingLogin
Machine Learning Academy · Lesson

The Equation of a Line: Slope, Intercept, and Predictions

Learners will recall the y=mx+b formula, plot a regression line on real data, and understand how the model maps inputs to outputs.

Linear Relationships in Data

Many real-world relationships are approximately linear: as square footage increases, house price increases proportionally; as advertising spend rises, sales rise. Linear regression models these relationships by finding the straight line that best fits the data.

Before tackling the algorithm, you need to deeply understand the mathematical object it is trying to find: the equation of a line. Every linear regression model is ultimately a line (in 2D) or a hyperplane (in higher dimensions), and the two parameters that define it — slope and intercept — carry meaningful interpretations for the problem you are solving.

The Equation y = mx + b

The equation of a line in 2D is y = mx + b, where:

  • y — the dependent variable (what we want to predict, e.g., house price)
  • x — the independent variable or feature (e.g., square footage)
  • m — the slope: how much y changes for each one-unit increase in x
  • b — the intercept: the value of y when x is zero

In machine learning notation, this is often written as ŷ = w₁x + w₀ or ŷ = θ₁x + θ₀, where w or θ are the weights (parameters) the model learns.

import numpy as np
import matplotlib.pyplot as plt

# Define a line: y = 2x + 5
m = 2.0   # slope
b = 5.0   # intercept

x = np.linspace(0, 10, 100)
y = m * x + b  # vectorised — computes all 100 points at once

plt.plot(x, y, color='blue', linewidth=2)
plt.xlabel('x (square footage / 100)')
plt.ylabel('y (price in $1000s)')
plt.title('Line: y = 2x + 5')
plt.grid(True, alpha=0.3)
plt.show()

All lessons in this course

  1. The Equation of a Line: Slope, Intercept, and Predictions
  2. Cost Functions and Least Squares
  3. Training Linear Regression with scikit-learn
  4. Multiple Linear Regression and Feature Importance
← Back to Machine Learning Academy