残差平方和
残差平方和(residual sum of squares,缩写:RSS)在统计学上是指将所有做预测时的误差值平方加起来得出的数:
R S S = ∑ i = 1 n e i 2 {\displaystyle RSS=\sum _{i=1}^{n}e_{i}^{2}\,}
它是衡量数据与估计模型之间差异的尺度。较小的残差平方和表示模型能良好地拟合数据。在确定参数和选择模型时,残差平方和是一种最优性准则。通常,总的方差=已经被模型解释了的平方和+残差平方和。
残差平方和这个数值在机器学习上是普通最小二乘法等算法的重心。
与皮尔逊相关系数的关系
对于两变量x和y, 它们的数据组的均值分别记为
x
¯
,
y
¯
{\displaystyle {\bar {x}},{\bar {y}}}
,则两数据组的皮尔逊相关系数为
r
=
S
x
y
S
x
x
S
y
y
{\displaystyle r={\frac {S_{xy}}{\sqrt {S_{xx}S_{yy}}}}}
,其中,
S
x
y
=
∑
i
=
1
n
(
x
¯
−
x
i
)
(
y
¯
−
y
i
)
{\displaystyle S_{xy}=\sum _{i=1}^{n}({\bar {x}}-x_{i})({\bar {y}}-y_{i})}
;
S
x
x
=
∑
i
=
1
n
(
x
¯
−
x
i
)
2
{\displaystyle S_{xx}=\sum _{i=1}^{n}({\bar {x}}-x_{i})^{2}}
;
S
y
y
=
∑
i
=
1
n
(
y
¯
−
y
i
)
2
{\displaystyle S_{yy}=\sum _{i=1}^{n}({\bar {y}}-y_{i})^{2}}
.
给定最小二乘回归线方程为
y
^
=
a
x
+
b
=
f
(
x
)
{\displaystyle {\hat {y}}=ax+b=f(x)}
, 其中
b
=
y
¯
−
a
x
¯
{\displaystyle b={\bar {y}}-a{\bar {x}}}
;
a
=
S
x
y
S
x
x
{\displaystyle a={\frac {S_{xy}}{S_{xx}}}}
. 则这时残差平方和可以表示为:
RSS
=
∑
i
=
1
n
(
y
i
−
f
(
x
i
)
)
2
=
∑
i
=
1
n
(
y
i
−
(
a
x
i
+
b
)
)
2
=
∑
i
=
1
n
(
y
i
−
a
x
i
−
y
¯
+
a
x
¯
)
2
=
∑
i
=
1
n
(
a
(
x
¯
−
x
i
)
−
(
y
¯
−
y
i
)
)
2
=
a
2
S
x
x
−
2
a
S
x
y
+
S
y
y
=
S
y
y
−
a
S
x
y
=
S
y
y
(
1
−
S
x
y
2
S
x
x
S
y
y
)
{\displaystyle {\begin{aligned}\operatorname {RSS} &=\sum _{i=1}^{n}(y_{i}-f(x_{i}))^{2}=\sum _{i=1}^{n}(y_{i}-(ax_{i}+b))^{2}=\sum _{i=1}^{n}(y_{i}-ax_{i}-{\bar {y}}+a{\bar {x}})^{2}\\[5pt]&=\sum _{i=1}^{n}(a({\bar {x}}-x_{i})-({\bar {y}}-y_{i}))^{2}=a^{2}S_{xx}-2aS_{xy}+S_{yy}=S_{yy}-aS_{xy}=S_{yy}\left(1-{\frac {S_{xy}^{2}}{S_{xx}S_{yy}}}\right)\end{aligned}}}
通过皮尔逊相关系数的公式,可以得到
RSS
=
S
y
y
(
1
−
r
2
)
{\displaystyle \operatorname {RSS} =S_{yy}(1-r^{2})}
.