Example: SLR

Mathematical Example of Simple Linear Regression

Let us understand how Simple Linear Regression works mathematically using a small dataset.

Problem Statement

Predict student marks based on study hours.

Dataset

Study Hours (X) Marks (Y)
1 10
2 20
3 30
4 40
5 50

Regression Equation

y = mx + b

Where:

  • y → Predicted value

  • x → Input value

  • m → Slope

  • b → Intercept

Step 1: Calculate Mean of X

mean_x = (1 + 2 + 3 + 4 + 5) / 5
mean_x = 3

Step 2: Calculate Mean of Y

mean_y = (10 + 20 + 30 + 40 + 50) / 5
mean_y = 30

Step 3: Calculate Slope (m)

Formula:

m = Σ[(X - mean_x)(Y - mean_y)] / Σ[(X - mean_x)^2]

Calculation Table

X Y X - mean_x Y - mean_y (X-mean_x)(Y-mean_y) (X-mean_x)^2
1 10 -2 -20 40 4
2 20 -1 -10 10 1
3 30 0 0 0 0
4 40 1 10 10 1
5 50 2 20 40 4

Sum Values

Σ[(X - mean_x)(Y - mean_y)] = 100
Σ[(X - mean_x)^2] = 10

Calculate Slope

m = 100 / 10
m = 10

Step 4: Calculate Intercept (b)

Formula:

b = mean_y - (m * mean_x)

Substitute values:

b = 30 - (10 * 3)
b = 0

Final Regression Equation

y = 10x + 0

or simply:

y = 10x

Step 5: Make Prediction

Suppose:

Study Hours = 6

Prediction:

y = 10 * 6
Predicted Marks = 60

Final Result

If a student studies for 6 hours,
the predicted marks will be 60.

Summary

In this example, we learned how Simple Linear Regression works mathematically using a small dataset. We calculated the mean of X and Y values, found the slope and intercept manually, and formed the final regression equation. Using this equation, we predicted new values based on input data. This example helps understand the mathematical foundation behind Linear Regression before implementing it in Python.

Keywords

Simple Linear Regression Example, Linear Regression Mathematical Example, Regression Equation, Slope and Intercept Calculation, Regression Formula, Mean Calculation in Regression, Regression Prediction Example, Supervised Learning Example, Linear Regression Mathematics, Regression Problem Solving, Machine Learning Regression Example

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What is the mean of X in the given dataset?

X Y
1 10
2 20
3 30
4 40
5 50

Mean of X = (1 + 2 + 3 + 4 + 5) / 5 = 3.

Question 2

What is the mean of Y in the dataset?

Mean of Y = (10 + 20 + 30 + 40 + 50) / 5 = 30.

Question 3

In the Linear Regression equation y = mx + b, what does "m" represent?

The slope (m) indicates how much the predicted value changes when the input value changes.

Question 4

What is the calculated slope (m) for the given dataset?

Using the slope formula, m = 100 / 10 = 10.

Question 5

What is the final regression equation obtained from the dataset?

The calculated slope is 10 and intercept is 0, so the regression equation is y = 10x.

Congratulations!

You've successfully mastered the knowledge check for "Example: SLR."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic Simple Linear Regression Next Topic Gradient Descent