Articles → MACHINE LEARNING → Simple Linear Regression Algorithm In Machine Learning

Simple Linear Regression Algorithm In Machine Learning






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




#average of x values (heights)
avg_x = (150 + 160 + 170) / 3 = 160  

#average of y values (weights)
avg_y = (50 + 56 + 63) / 3 = 56.33




Picture showing formula for calculating slope


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


#Calculating the numerator for the calculation of slope
Σ[(x - avg_x)(y - avg_y)] = 63.3 + 0 + 66.7 = 130  

#Calculating the denominator for the calculation of slope
Σ[(x - avg_x)²] = 100 + 0 + 100 = 200  

#value of slope
m = 130/200 = 0.65



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



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
 
Updated On  -  Saturday, September 27, 2025

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250