# 最小二乘法 来龙去脉

## 1.最小二乘的背景

1801年，意大利天文学家朱赛普·皮亚齐发现了第一颗小行星谷神星。经过40天的跟踪观测后，由于谷神星运行至太阳背后，使得皮亚齐失去了谷神星的位置。随后全世界的科学家利用皮亚齐的观测数据开始寻找谷神星，但是根据大多数人计算的结果来寻找谷神星都没有结果。时年24岁的高斯也计算了谷神星的轨道。奥地利天文学家海因里希·奥伯斯根据高斯计算出来的轨道重新发现了谷神星。

## 3.最小二乘的cost function

$Q=min\sum _{i}^{n}\left({y}_{ie}-{y}_{i}{\right)}^{2}$

## 4.最小二乘法的求解

$Q=\sum _{i}^{n}\left({y}_{i}-{\beta }_{0}-{\beta }_{1}x{\right)}^{2}$

$\frac{\mathrm{\partial }Q}{\mathrm{\partial }{\beta }_{0}}=2\sum _{i}^{n}\left({y}_{i}-{\beta }_{0}-{\beta }_{1}{x}_{i}\right)\left(-1\right)=0\phantom{\rule{0ex}{0ex}}\frac{\mathrm{\partial }Q}{\mathrm{\partial }{\beta }_{1}}=2\sum _{i}^{n}\left({y}_{i}-{\beta }_{0}-{\beta }_{1}{x}_{i}\right)\left(-{x}_{i}\right)=0$

${\beta }_{0}=\frac{\sum {x}_{i}^{2}\sum {y}_{i}-\sum {x}_{i}\sum {x}_{i}{y}_{i}}{n\sum {x}_{i}^{2}-\left(\sum {x}_{i}{\right)}^{2}}\phantom{\rule{0ex}{0ex}}{\beta }_{1}=\frac{n\sum {x}_{i}{y}_{i}-\sum {x}_{i}\sum {y}_{i}}{n\sum {x}_{i}^{2}-\left(\sum {x}_{i}{\right)}^{2}}$

## 5.矩阵表达形式

$y\left({x}^{1},\cdots ,{x}^{m};{\beta }_{0},\cdots ,{\beta }_{m}\right)={\beta }_{0}+{\beta }_{1}{x}^{1}+\cdots +{\beta }_{m}{x}^{m}$

${\beta }_{0}+{\beta }_{1}{x}_{1}^{1}+\cdots +{\beta }_{j}{x}_{1}^{j}+\cdots +{\beta }_{m}{x}_{1}^{m}={y}_{1}\phantom{\rule{0ex}{0ex}}{\beta }_{0}+{\beta }_{1}{x}_{2}^{1}+\cdots +{\beta }_{j}{x}_{2}^{j}+\cdots +{\beta }_{m}{x}_{2}^{m}={y}_{2}\phantom{\rule{0ex}{0ex}}\cdots \phantom{\rule{0ex}{0ex}}{\beta }_{0}+{\beta }_{1}{x}_{i}^{1}+\cdots +{\beta }_{j}{x}_{i}^{j}+\cdots +{\beta }_{m}{x}_{i}^{m}={y}_{i}\phantom{\rule{0ex}{0ex}}\cdots \phantom{\rule{0ex}{0ex}}{\beta }_{0}+{\beta }_{1}{x}_{n}^{1}+\cdots +{\beta }_{j}{x}_{n}^{j}+\cdots +{\beta }_{m}{x}_{n}^{m}={y}_{n}$

$\left[\begin{array}{cccc}1& {x}_{1}^{\left(1\right)}& \cdots & {x}_{1}^{\left(m\right)}\\ 1& {x}_{2}^{\left(1\right)}& \cdots & {x}_{2}^{\left(m\right)}\\ \cdots & \cdots & \cdots & \cdots \\ 1& {x}_{n}^{\left(1\right)}& \cdots & {x}_{n}^{\left(m\right)}\end{array}\right]\cdot \left[\begin{array}{c}{\beta }_{0}\\ {\beta }_{1}\\ \cdots \\ {\beta }_{m}\end{array}\right]=\left[\begin{array}{c}{y}_{1}\\ {y}_{2}\\ \cdots \\ {y}_{n}\end{array}\right]$

$A\beta =Y$$A \beta = Y$

$min||A\beta -Y|{|}_{2}$

$\beta =\left({A}^{T}A{\right)}^{-1}{A}^{T}Y$

## 6.注意事项

01-07

09-26

12-10

10-05 1295

07-09 1101

01-28 2万+

02-14 7万+

03-02 1154

12-10 2276

04-25 4847

04-15 4792

05-04 4万+

12-28 10万+

02-07 9万+

11-12 1万+

07-20 10万+

07-25 9211

12-08 2万+

11-15 697

04-20 3万+

02-11 2万+

12-12 1万+

03-28 231

07-14 54

06-07 2万+

03-26 4991

07-26 1358

#### 最小二乘法与最小一乘法

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客