VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/ml-mathematical-explanation-of-rmse-and-r-squared-error/

⇱ ML | Mathematical explanation of RMSE and R-squared error - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ML | Mathematical explanation of RMSE and R-squared error

Last Updated : 6 Jun, 2022

RMSE: Root Mean Square Error is the measure of how well a regression line fits the data points. RMSE can also be construed as Standard Deviation in the residuals. 

Consider the given data points: (1, 1), (2, 2), (2, 3), (3, 6). 

Let us break the above data points into 1-d lists. 

Input: 

x = [1, 2, 2, 3]
y = [1, 2, 3, 6]

Code: Regression Graph  

Output: 

👁 Image

Code: Mean Calculation 

Output : 

Value of X mean 2.0
value of Y mean 3.0

Code: Line Equation  

Output: 

Intercept -2.0

Code: Mean Squared Error

Output:

👁 Image

Output: 

Root mean square error 0.6123724356957945

Code : RMSE Calculation  

Output:

👁 Image

Output: 

Root Mean square error using maths 0.6123724356957945

R-squared Error or Coefficient of Determination 
R2 error answers the below question. 
How much y varies with variation in x.Basically the % variation of y on variation with x

👁 Image

Code: R-Squared Error  


Output
('val', 0.25, 1.0, 0.0, 0.25)
('Rsquared error', 0.8928571428571429)

Code: R-Squared Error with sklearn 

Output: 

0.8928571428571429 
Comment