Skip to content

Linear Regression: Predicting Numbers with a Line

Beginning of the lesson

Linear Regression: Predicting Numbers with a Line

Imagine you have a handful of dots scattered on a graph — each dot is a real apartment, its area on the bottom axis and its price up the side. You can see a rough trend: bigger apartments cost more. Linear regression is simply the art of drawing the one straight line that runs through the middle of those dots as well as possible, and then using that line to guess the price of an apartment you have never seen before.

That is the whole idea. A machine "learns" a line from examples, and afterwards the line becomes a prediction machine: give it an area, it hands you back a price. In this lesson we will build that line by hand with real numbers, learn exactly what "best" means, and see how a computer nudges the line into place step by step.

What you will be able to do after this lesson
  • Explain what a straight-line model $y = w\,x + b$ means, in plain words, and what the slope $w$ and intercept $b$ each control.
  • Use a fitted line to predict a number (like an apartment price) from an input (like area).
  • Measure how good a line is using residuals, squaring, and Mean Squared Error (MSE) — computed by hand.
  • Describe how gradient descent "walks downhill" to find the best line, and what a learning rate does.
  • Extend the line to many features (a weighted sum) and read the weights — carefully — as feature importance.
  • Know where linear regression works and where it fails, and read R-squared as a percentage of variation explained.
  • Fit a real model in a few lines of Python with scikit-learn.

  The big idea: a line that turns an input into a prediction

A line is the simplest possible relationship between two numbers. Every straight line can be written with one small formula:

$$y = w\,x + b$$

Let us decode every symbol, because these five characters carry the whole lesson:

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 16
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers