Machine Learning

Linear Regression

Lesson 3 · Machine Learning

Linear Regression

8 min

You'll be able to

  • Understand the equation of a line in data terms
  • Explain what the model learns
  • Interpret coefficients meaningfully

Linear regression models a target as a weighted sum of features plus a bias. If y is price and x is square footage, we predict y = w·x + b, where w is a weight and b a bias.

Training finds the w and b that minimise the difference between predictions and actual values — usually measured by mean squared error.

Training a linear model with NumPy-style logic
import numpy as np

# data: square footage -> price
x = np.array([800, 1000, 1200, 1500])
y = np.array([120, 150, 180, 230])

# closed-form least squares
w, b = np.polyfit(x, y, 1)
print(f"price = {w:.2f} * sqft + {b:.2f}")

Challenge

Fit by hand

Given points (1,2), (2,4), (3,6), guess a simple w and b that fit perfectly. Confirm the pattern.

Knowledge Check

Linear regression

0/2 answered

Linear regression is a type of classification task.

In y = w·x + b, what does the model learn during training?

Answer all questions to submit.

Search AmineX

Search courses, lessons, projects and concepts