回顾最小二乘法
最小二乘法的用途 最小二乘法来常常用来估计线性回归中的斜率,以作线性最小二乘拟合 linear least squares fit res = ys – (inter + slope * xs) res: 残差 ys: 因变量序列 xs: 自变量序列 inter: 截距 slope: 斜率 最好是找到合适的 inter 和 slope 使残差的绝对值最小,常见的做法是使得残差的平方和最小, 因为平方和与残差的正负值无关,并使较大的残差具有更多的权重。 ··· sum(res**2) ··· 最小二乘法说明 具体算法参见 https://en.wikipedia.org/wiki/Numerical_methods_for_linear_least_square 和 https://zh.wikipedia.org/wiki/%E6%9C%80%E5%B0%8F%E4%BA%8C%E4%B9%98%E6%B3%95 线性函数模型 Q = \sum_{i=1}^{n} \ [y_i – f(\vec{x}_i;\hat{\vec{\beta}})]^2 y = \beta_0 + \beta_1x + \varepsilon \, […]