MATLAB: How to enter the R-square fit formula in the m-file

r-square fit

I need to calculate the R-square fit for the model output. I have the formula for calculating it, but how to give it in the code and what is the plot command to get the r-square fit?
Please do help me.

Best Answer

Residual sum of squares
residsumsq = norm(y-yhat,2)^2;
Total sum of squares
tsumsq = norm(y-mean(y),2)^2;
R2 = 1-(tsumsq/residsumsq);
Related Question