What is the formula for R squared?
What is the formula for R squared?
First, we must measure the total sum of the squares. y_i is the observed value of the response variable for the ith test instance, and y_bar is the mean of the observed values of the response variable
SS_tot = SUM( (y_i - y_bar)^2 )
Next, we must find the residual sum of the squares. Recall that this is also our cost function.
SS_res = SUM( (y_i - f(x_i)) ^ 2 )
Finally, we can find r-squared using the following formula:
R^2 = 1 - (SS_res / SS_tot)