Cycoe@Home

一種通過最小二乘法求轉變點的方法

1. 最小二乘法

假設存在 \(k\) 個樣本點 \(X_1, X_2, \ldots, X_k\),定義向量 \(X_i = (x_{i1}, x_{i2}, \ldots, x_{in})^T\),爲方便計算在 \(X_i\) 前插入常量 1。則需要求 \(W = (w_0, w_1, w_2, \ldots, w_n)\) 使 \(\hat{Y} = XW\)。

定義均方誤差 \(E = \dfrac{1}{n}\sum(y_i-\hat{y}_i)^2 = \dfrac{1}{n}||Y-\hat{Y}||_2^2\),則可轉變爲尋找 \(W\) 使得 \(E\) 最小,即尋找\(W = \mathrm{argmin}\dfrac{1}{n}||Y-XW||_2^2\)。

對於

\begin{equation} E(W) = \dfrac{1}{n} \end{equation}

則可推導

\begin{equation} \begin{aligned} E(W+\Delta W) - E(W) &= \dfrac{1}{n}||Y-X(W+\Delta W)||_2^2-\dfrac{1}{n}||Y-XW||_2^2\\ &= \dfrac1n||Y-XW||_2^2-\dfrac2n(Y-XW)(X\Delta W)+\dfrac1n||X\Delta W||_2^2-\dfrac1n||Y-XW||_2^2\\ &= \dfrac2n(XW-Y)X\Delta W+\mathcal{O}(||\Delta X||)\\ \end{aligned} \end{equation}

\begin{equation} L(W) = \dfrac2n(XW-Y)X\Delta W \end{equation}

爲 \(E(W)\) 在 \(W\)處的導數,同時

\begin{equation} \begin{aligned} L(\Delta W) &= <\nabla E(W), \Delta W>\\ &= <\dfrac2nX^T(XW-Y), \Delta X>\\ &= \dfrac2n(XW-Y)X\Delta W\\ \end{aligned} \end{equation}

\begin{equation} \begin{aligned} \nabla E(W) = \dfrac2nX^T(XW-Y) &= 0\\ X^TXW &= X^TY\\ W &= (X^TX)^{-1}X^TY \end{aligned} \end{equation}

最終得

\begin{equation} E=\dfrac1n||Y-\hat{Y}||_2^2=\dfrac1n||X(X^TX)^{-1}X^TY-Y||_2^2 \end{equation}
Author: Cycoe (cycoejoo@163.com)
Date: <2018-10-23 Tue 21:52>
Generator: Emacs 29.1 (Org mode 9.6.6)
Built: <2024-01-27 Sat 21:20>