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

Previous Topic Simple Linear Regression Next Topic ML Projects