Open In App

R-squared in Regression Analysis in Machine Learning

The most important thing we do after making any model is evaluating the model. We have different evaluation matrices for evaluating the model. However, the choice of evaluation matrix to use for evaluating the model depends upon the type of problem we are solving whether it’s a regression, classification, or any other type of problem.  In this article, we will explain R-Square for regression analysis problems.

What is R-Squared 

R-squared is a statistical measure that represents the goodness of fit of a regression model. The value of R-square lies between 0 to 1. Where we get R-square equals 1 when the model perfectly fits the data and there is no difference between the predicted value and actual value.  However, we get R-square equals 0 when the model does not predict any variability in the model and it does not learn any relationship between the dependent and independent variables.



How is R-Squared Calculated

R-squared also known as the coefficient of determination measures the variability in the dependent variable Y that is being explained by the independent variables Xi in the regression model. 

We calculate R-Square in the following steps



  1.  First, calculate the mean of the target/dependent variable y and we denote it by y̅
  2.  Calculate the total sum of squares by subtracting each observation yi from y̅, then squaring it and summing these square differences across all the values. It is denoted by  
  3. We estimate the model parameter using a suitable regression model such as Linear Regression or SVM Regressor  
  4. We calculate the Sum of squares due to regression which is denoted by SSR. This is calculated by subtracting each predicted value of y denoted by y_predi from yi squaring these differences and then summing all the n terms. SSR = \sum_{i=1}^{n} (\hat{ypred}_i – \bar{y})^2  
  5. We calculate the sum of squares (SSres). It explains unaccounted variability in the dependent y after predicting these values from an independent variable in the model.  SSres = \sum_{i=1}^n (y_i – {ypred}_i)^2
  6. we can then use either 

R-Squared Goodness Of Fit  

R-square is a comparison of the residual sum of squares (SSres) with the total sum of squares(SStot). The total sum of squares is calculated by summation of squares of perpendicular distance between data points and the average line.  

The residual sum of squares is calculated by the summation of squares of perpendicular distance between data points and the best-fitted line. 

 

R square is calculated by using the following formula :

  

Where SSres is the residual sum of squares and SStot is the total sum of squares. 

The goodness of fit of regression models can be analyzed on the basis of the R-square method. The more the value of the r-square near 1, the better the model is. 

Note: The value of R-square can also be negative when the model fitted is worse than the average fitted model. 

Limitation of using the R-square method –

R-Squared Vs Adjusted R-Squared

Adjusted R-Squared is an updated version of R-squared which takes account of the number of independent variables while calculating R-squared. The main problem with R-squared is that the R-Square value always increases with an increase in independent variables irrespective of the fact that where the independent variable is contributing to the model or not. This leads to the model having high variance if the model has a lot of independent variables.

Formula For Adjusted R-Squared

Article Tags :