對於m個樣本
某模型的估計值為
計算樣本的總平方和TSS(Total Sum of Squares):
計算殘差平方和RSS(Residual Sum of Squares):
RSS即誤差平方和SSE(Sum of Squares for Error)
定義 R2=1-RSS/TSS
R2越大,擬合效果越好
R2的最優值為1
若預測值恆為樣本期望,R2為0
亦可定義ESS(Explained Sum of Squares):
TSS=ESS+RSS
只有在無偏估計時上述等式才成立,否則,TSS≥ESS+RSS
ESS又稱回歸平方和SSR(Sum of Squares for Regression)