AI engineering glossary · Classical ML algorithms
What is linear regression?
Linear regression: A supervised method that predicts a number as a weighted sum of input features plus a constant. Training picks the weights that make predictions as close as possible to the known answers, usually by minimising squared error. It is fast, easy to interpret and a standard baseline for numeric prediction.
Linear regression: an example
Predicting a flat's monthly rent in Bengaluru as 4000 + 25 * area_sqft + 3000 * bedrooms; a 900 sqft 2-bedroom flat gives 4000 + 22500 + 6000 = 32,500 rupees.
Linear regression in Python
A short example you can run (Python 3.11, NumPy). The output below is what it really prints.
import numpy as np
sqft = np.array([500, 750, 1000, 1250, 1500])
rent = np.array([12000, 16500, 21000, 25000, 30000]) # rupees per month (made-up data)
slope, intercept = np.polyfit(sqft, rent, 1)
print(f"rent = {slope:.2f} * sqft + {intercept:.0f}")
print("predicted rent for 1100 sqft:", round(slope * 1100 + intercept))Output
rent = 17.80 * sqft + 3100 predicted rent for 1100 sqft: 22680
Related terms
More Classical ML algorithms terms
- Linkage criterion
- Local outlier factor
- Log-odds
- Logistic regression
- Manhattan distance
- Matrix factorisation
- Maximum margin classifier
- Mini-batch k-means
Where you learn it
Linear regression is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.