Curvingo · Made in India

Glossary

Select one of the keywords on the left…

Linear RegressionIntroduction

Reading time: ~10 min

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 x. For Riya, the feature is the .
  • The thing we want to predict is called the target, written y. For Riya, the target is the .
  • The model's guess for the target is the prediction, written \hat{y} and read "y-hat".

Our model is a straight line, the same y = mx + c you met in the Straight Lines chapter: \hat{y} = mx + c, where m is the slope and c is the intercept. Training the model means finding the values of m and c that fit the past data best. After that, predicting is just substitution: if the model were \hat{y} = 5x - 60, a 30 °C day would give \hat{y} = kulfis.

Note

Machine-learning books write the same line as \hat{y} = wx + b: w is called the weight and b the bias. With more than one feature it becomes \hat{y} = w_1x_1 + w_2x_2 + \dots + b. 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.

Tomorrow's temperature
Is this SMS spam?
Price of a used phone
Pass or fail in a unit test
Marks in the board exam
Which fruit is in this photo?
Kulfis to make tomorrow
Will it rain tomorrow: yes or no?
A number — regression
A group — classification
Sina