Linear RegressionIntroduction
Riya runs a kulfi cart outside her school gate. Every evening she writes two numbers in her notebook: the afternoon temperature and how many kulfis she sold. Kulfis that she makes but cannot sell melt away; kulfis she does not make are customers she loses. So every morning she has to make a guess.
Tomorrow's forecast says 38 °C. How many kulfis should she make?
Here are her last ten days. Each blue dot is one day: how hot it was, and how many kulfis she sold. Drag the two purple knobs until the line runs through the middle of the dots. The amber marker shows what your line predicts for a 38 °C day.
You just did, by eye, what a machine-learning model does with maths. You looked at past examples, spotted the pattern — hotter day, more kulfis — drew a straight line through it, and then used the line to predict a day that has not happened yet. That is linear regression, and it is the "Hello World" of machine learning: almost every bigger idea in the field grows out of it.
The Words Machine Learning Uses
Every machine-learning problem has something we know and something we want to find out.
- The thing we know in advance is called a feature, written . For Riya, the feature is the
. - The thing we want to predict is called the target, written . For Riya, the target is the
. - The model's guess for the target is the prediction, written and read "y-hat".
Our model is a straight line, the same you met in the Straight Lines chapter: , where is the
Note
Machine-learning books write the same line as : is called the weight and the bias. With more than one feature it becomes . Learning from examples that come with the right answers, like Riya's notebook, is called supervised learning.
Number or Category?
Regression is for questions whose answer is a number on a scale, like 128 kulfis or 37.5 °C. When the answer is one of a few groups — spam or not spam, pass or fail — the job is called classification. Sort these questions.