Linear Regression

Learn how to find the line of best fit for data and use it to make predictions.

Advanced25 minLesson

Definition

Linear regression is a statistical method for finding the straight line that best fits a set of data points. This line, called the line of best fit or regression line, minimizes the distances between the line and all the data points.
The equation of the regression line is:
Where:
  • is the slope (how much changes for each unit increase in )
  • is the y-intercept (the value of when )
The least squares method finds the line that minimizes the sum of squared distances (residuals) from each point to the line:

Try it now

What does the slope in a regression line represent?

Worked Examples

A coffee shop tracks daily temperature (°C) and iced coffee sales: | Temperature | Sales | |-------------|-------| | 15 | 20 | | 20 | 35 | | 25 | 45 | | 30 | 60 | | 35 | 70 | Find the equation of the regression line.

1

Calculate the means

,

2

Calculate slope using the formula

Numerator: Denominator:

3

Calculate y-intercept

4

Write the regression equation

Regression line:

Common Mistakes

Assuming the regression line passes through all data points

Why it's wrong: The line of best fit minimizes total error but rarely passes through every point. Points above and below the line are normal.

Correct: Understand that the regression line represents the overall trend, not individual data points.

Using the regression equation for extrapolation far beyond the data range

Why it's wrong: The relationship may not hold outside the range of observed data. Predicting far beyond your data can give unrealistic results.

Correct: Be cautious when predicting for x-values far outside your data range. Note when you're extrapolating.

Confusing correlation with causation

Why it's wrong: A strong linear relationship doesn't mean one variable causes changes in the other. There may be other factors involved.

Correct: Use regression to describe relationships and make predictions, but be careful about claiming causation.

Forgetting to check if a linear model is appropriate

Why it's wrong: Not all data follows a linear pattern. Using linear regression on non-linear data gives misleading results.

Correct: Always plot your data first. If the scatter plot shows a curve, linear regression may not be the best choice.

Interactive Visual

Linear Function Explorer

y = x
Slope (m)1
Y-Intercept (b)0
b
run
rise
xy
-2-2
-1-1
00
11
22

Interactive Sandbox

Interactive Grapher

Try these examples:

y = 2x + 1

m=2, b=1

Expression Calculator

Try these:

History

No calculations yet

Practice Problems

16 problems
Problem 1 of 16
Easy

What does the slope in a regression line represent?

Why It Matters

Linear regression is one of the most important tools in data analysis:
  • Business: Predict sales based on advertising spending or price changes
  • Science: Model relationships between variables in experiments
  • Medicine: Predict patient outcomes based on treatment data
  • Economics: Forecast economic indicators based on historical trends
  • Sports: Analyze player performance and predict future statistics
Understanding regression helps you make data-driven predictions and identify trends that would be impossible to see by just looking at raw numbers.

Real World Applications

Predicting Housing Prices

Real estate analysts use linear regression to estimate home prices based on features like square footage, number of bedrooms, or distance from city center.

Example:

If where is square meters and is price in euros, a 100 m² apartment would cost about 150(100) + 50000 = 65000 euros.

1Try It Yourself

A real estate model shows: Price = 200x + 30000 (where x = square meters).

What price would you predict for a 120 m² apartment?

Step 1: Write the mathematical expression

Substitute into the equation:

Fuel Efficiency Analysis

Automotive engineers use regression to understand how car weight affects fuel consumption.

Example:

If fuel consumption (L/100km) = 0.004 × weight (kg) + 2, a 1500 kg car would use 0.004(1500) + 2 = 8 L/100km.

2Try It Yourself

A car manufacturer's data shows: Fuel = 0.005w + 1.5 (where w = weight in kg).

Predict fuel consumption for a 1200 kg vehicle.

Step 1: Write the mathematical expression

Calculate:

Business Sales Forecasting

Companies use regression to predict future sales based on advertising spending, helping them allocate marketing budgets effectively.

Example:

If monthly sales = 3 × ad spending + 10000, spending 5000 euros on ads predicts sales of 3(5000) + 10000 = 25000 euros.

3Try It Yourself

A company's model: Sales = 4 × AdBudget + 8000.

If they spend 3000 euros on advertising, what sales can they expect?

Step 1: Write the mathematical expression

Calculate predicted sales:

Key Takeaways

  • 1Linear regression finds the line that best fits a set of data points
  • 2The regression line equation is where is slope and is y-intercept
  • 3Slope tells you how much changes for each unit increase in
  • 4The y-intercept is the predicted value of when
  • 5Use regression to make predictions, but be cautious about extrapolating far beyond your data

Frequently Asked Questions

If your scatter plot shows a curve rather than a straight line, linear regression may not be appropriate. Consider polynomial regression or other non-linear models instead.
If your scatter plot shows a curve rather than a straight line, linear regression may not be appropriate. Consider polynomial regression or other non-linear models instead.
No. Regression shows relationships (correlations) but cannot prove causation. Two variables might be related because of a third factor, not because one causes the other.
A residual is the difference between an actual data point and the predicted value from the regression line: residual = . Positive residuals mean the point is above the line; negative means below.

Glossary

Linear regression
A statistical method for finding the straight line that best fits a set of data points
Line of best fit
The regression line that minimizes the sum of squared residuals
Slope
The rate of change; how much increases for each unit increase in
Y-intercept
The value of when ; where the line crosses the y-axis
Residual
The difference between an actual data point and its predicted value on the regression line
Least squares
The method that finds the line minimizing the sum of squared residuals
Extrapolation
Using a regression equation to predict values outside the range of the original data

Formula Card

Regression Line

The equation of the line of best fit where m is slope and b is y-intercept

Slope Formula

Calculate the slope from data points using means and deviations

Y-Intercept

Calculate the y-intercept using the slope and the means of x and y

Residual

The difference between actual and predicted values for each point

More in This Topic