For Linear Regression, R-squared is a statistical term which indicates how close the data are to the fitted regression line.
R-Squared is also known as coefficient of determination.
R-squared = Explained variation in data / Total variation in data
R-squared = 1 – (RSS/TSS)
RSS = Sum of squares of difference between predicted value and actual value
TSS = Sum of squares of difference between mean value and actual value
How to calculate R-Squared using Sklearn for Linear Regression.
from sklearn.metrics import r2_score
rsquared = r2_score(y_true,y_pred)
Below picture depicts how all the data point may not fall on the fitted regression line.
Note that the value of R-squared does not indicate the performance of the Linear Regression model, hence you should analyze residuals by calculating Root Mean Squared Error or RMSE as well.
If you have any query related to above post please feel free to post a comment.
One thought on “What is R Squared for Linear Regression”