MACHINE LEARNING • LESSON 7

Understanding the Line

In Linear Regression, the model learns a line that represents the relationship between the input features and the numerical output.

THE SIMPLEST DEFINITION

The line is the relationship learned by the model.

Once the model learns this relationship, it can use the line to estimate the output for new input values.

01

Start With Some Data

Suppose we want to predict an exam score from the number of hours a student studies.

Study Hours Actual Score
1 hour 45
2 hours 55
3 hours 65
4 hours 75
5 hours 85

These are examples the model can learn from.

02

The Model Finds a Line

The model looks at the relationship between study hours and exam scores and finds a line that represents the overall pattern.

::contentReference[oaicite:0]{index=0}

The individual data points represent observations. The line represents the relationship learned by the Linear Regression model.

03

What Does the Line Tell Us?

The line tells us how the predicted output changes as the input changes.

More study hours → higher predicted exam score

This does not mean that every student will follow the relationship perfectly. It means the model has learned this general pattern from the training data.

04

The Equation of the Line

A simple regression line can be written as:

ŷ = b₀ + b₁x
ŷ Predicted output
x Input feature
b₀ Intercept
b₁ Slope

The two important parts of the line to understand are the slope and the intercept.

05

Understanding the Slope

The slope tells us how much the predicted output changes when the input increases by one unit.

Suppose our model learns:

Score = 35 + 10 × Study Hours

Here, 10 is the slope.

Every additional study hour changes the predicted score by 10 points in this example.

So:

STUDY HOURS 2
PREDICTED SCORE 55
STUDY HOURS 3
PREDICTED SCORE 65

Increasing study hours from 2 to 3 increases the predicted score by 10.

06

Positive and Negative Slope

The sign of the slope tells us the direction of the relationship.

POSITIVE SLOPE Input increases → prediction increases

Example: Study Hours → Exam Score

NEGATIVE SLOPE Input increases → prediction decreases

Example: House Age → Predicted House Price

A positive slope means the line goes upward. A negative slope means the line goes downward.

07

Understanding the Intercept

The intercept is the predicted output when the input value is zero.

Using our equation:

Score = 35 + 10 × Study Hours

If study hours are zero:

Score = 35 + 10 × 0 Score = 35

Therefore, the intercept in this example is 35.

Intercept = where the regression line crosses the output axis when the input is zero.

One important caution: the intercept is not always meaningful in the real world if an input value of zero is impossible or outside the useful range of the data.

08

Using the Line to Make a Prediction

Once the model has learned the line, we can give it a new input.

Suppose a new student studies for 6 hours.

NEW INPUT 6 hours
REGRESSION LINE Score = 35 + 10x
PREDICTION 95

The line converts the new input into a predicted output.

09

Why Don't All Data Points Sit on the Line?

Real-world data is rarely perfect.

For example, two students may study for the same number of hours but receive different scores because of preparation, difficulty of the exam, sleep, stress, and many other factors.

STUDY HOURS 4 hours
ACTUAL SCORE 70
MODEL PREDICTION 75

The difference between the actual value and the predicted value is called the residual or prediction error.

The regression line represents the overall relationship, not every individual observation perfectly.

10

What Makes a Good Regression Line?

A good regression line should produce predictions that are reasonably close to the actual values in data the model has not seen.

POOR LINE Large prediction errors

Predictions are far from actual values.

BETTER LINE Smaller prediction errors

Predictions are generally closer to actual values.

Later, in the Evaluate a Regression Model topic, we will learn how to measure these errors using metrics such as MAE, MSE, and R².

REMEMBER THIS

The regression line is the relationship learned by the model.

The slope tells us how the prediction changes as an input changes. The intercept represents the predicted output when the input is zero. The line is then used to make predictions for new inputs.

QUICK CHECK

Understand the Line

What does the slope tell us? How the predicted output changes when the input changes.
What does the intercept represent? The predicted output when the input is zero.
Why are points not always on the line? Real-world data contains variation and prediction errors.
NEXT TOPIC

Prediction With Linear Regression

Next, we will take new input data and see exactly how a trained Linear Regression model produces a prediction.