Articles → MACHINE LEARNING → Linear Regression Algorithm

Linear Regression Algorithm






What Is The Linear Regression Algorithm?




  1. Taller people tend to weigh more.
  2. Shorter people tend to weigh less.



Formula For Calculating A Straight Line


y = mx + c


Formula PartDescription
yAverage of target (or output variable)
xAverage of the Input variable
mThe slope (how much y changes for each x). The slope is also known as the Coefficient.
cThe intercept (where the line crosses the y-axis), i.e., what is the value of Y when X is zero?



Example




HeightWeight
150 cm50 kg
160 cm56 kg
170 cm63 kg




  1. avg_x = average of x values (heights)
  2. avg_y = average of y values (weights)
avg_x = (150 + 160 + 170) / 3 = 160  
avg_y = (50 + 56 + 63) / 3 = 56.33




m = Σ[(xi - avg_x)(yi - avg_y)] / Σ[(xi - avg_x)²]


xyxi - avg_xyi - avg_y(xi - avg_x)(yi - avg_y)(xi - avg_x)²
15050-10-6.3363.3100
160560-0.3300
17063106.6766.7100


Σ[(x - avg_x)(y - avg_y)] = 63.3 + 0 + 66.7 = 130  
Σ[(x - avg_x)²] = 100 + 0 + 100 = 200  






c = avg_y − m × avg_x 
c = 56.33 − 0.65 × 160  
c = 56.33 − 104 = -47.67



Error




Error = Y (Actual) – Y (Predicted)




y = (0.65)X +(-47.67) // mx + c


HeightWeight (Actual)Weight (Predicted) – CalculationWeight (Predicted)Error
150500.65×150−47.67 49.830.17
160560.65×160−47.67 56.33-0.33
170630.65×170−47.67 62.830.17



Mean Squared Error (MSE)






Picture showing the formula of Mean Squared Error




Picture showing the calculation of Mean Squared Error





Root Mean Squared Error (RMSE)




Picture showing the formula of Root Mean Squared Error


Picture showing the calculation of Root Mean Squared Error



Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, May 20, 2025

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250