Understanding the Line
In Linear Regression, the model learns a line that represents the relationship between the input features and the numerical output.
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.
Start With Some Data
Suppose we want to predict an exam score from the number of hours a student studies.
These are examples the model can learn from.
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.
The individual data points represent observations. The line represents the relationship learned by the Linear Regression model.
What Does the Line Tell Us?
The line tells us how the predicted output changes as the input changes.
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.
The Equation of the Line
A simple regression line can be written as:
The two important parts of the line to understand are the slope and the intercept.
Understanding the Slope
The slope tells us how much the predicted output changes when the input increases by one unit.
Suppose our model learns:
Here, 10 is the slope.
So:
Increasing study hours from 2 to 3 increases the predicted score by 10.
Positive and Negative Slope
The sign of the slope tells us the direction of the relationship.
Example: Study Hours → Exam Score
Example: House Age → Predicted House Price
A positive slope means the line goes upward. A negative slope means the line goes downward.
Understanding the Intercept
The intercept is the predicted output when the input value is zero.
Using our equation:
If study hours are zero:
Therefore, the intercept in this example is 35.
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.
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.
The line converts the new input into a predicted output.
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.
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.
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.
Predictions are far from actual values.
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².
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.