局部加權回歸LOWESS


1. LOWESS

用kNN做平均回歸:

\[\hat{f(x)} = Ave(y_i | x_i \in N_k(x)) \]

其中,\(N_k(x)\)為距離點x最近k個點組成的鄰域集合(neighborhood set)。這種鄰域平均回歸存在很多缺點:

  • 沒有考慮到不同距離的鄰近點應有不同的權重;
  • 擬合的曲線不連續(discontinuous),如下圖。

因此引入kernel加權平滑:

\[\hat{f(x_0)} = \frac{ \sum_{i=1}^{N} K_{\lambda}(x_0, x_i)y_i }{\sum_{i=1}^{N} K_{\lambda}(x_0, x_i)} \]

比如,Epanechnikov 二次kernel:

\[K_{\lambda}(x_0, x_i) = D(\frac{|x_0 - x_i|}{\lambda}) \]

\[D(t) = \left \{ { \matrix { {\frac{3}{4} (1-t^2) } & {for |t| < 1} \cr { 0} & {otherwise} \cr } } \right. \]

其中,\(\lambda\)為kernel的參數,稱之為window width。對於kNN,只考慮最近的k個點影響;基於此,

\[\lambda = |x_0 - x_{[k]}| \]

其中,\(x_{[k]}\)為距離\(x_0\)第k近的點。如上圖,經kernel加權平滑后,回歸擬合的曲線為連續的了。但是,這種kernel回歸同樣存在着邊界(boundary)問題,如下圖:

對於x序列的開始與結束區段的點,其左右鄰域是不對稱的,導致了平滑后的值偏大或偏小。因此,需要對權值做再修正,假定對\(x_0\)的估計值:_

\[\hat{f(x_0)} = \sum_{j=0}^d \beta_j x_0^{j} \]

定義目標函數:

\[\min_{\beta} \sum_{i=1}^N K_{\lambda}(x_0, x_i) [y_i - \sum_{j=0}^d \beta_j x_i^j]^2 \]

\[B = \begin{pmatrix} 1 & x_1 & \cdots & x_1^d \\ 1 & x_2 & \cdots & x_2^d \\ \vdots & \vdots & \ddots & \vdots \\ 1 & x_N & \cdots & x_N^d \\ \end{pmatrix} \]

\[W_{x_0} = \begin{pmatrix} K_{\lambda}(x_0, x_1) & 0 & \cdots & 0 \\ 0 & K_{\lambda}(x_0, x_2) & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & K_{\lambda}(x_0, x_N) \\ \end{pmatrix} \]

\[\Delta = \begin{pmatrix} \beta_0, \beta_1, \cdots, \beta_d \end{pmatrix}^T \]

\[Y = \begin{pmatrix} y_1, y_2, \cdots, y_N \end{pmatrix}^T \]

那么,目標函數可改寫為

\[\min_{\Delta} (Y-B\Delta)^T W_{x_0} (Y-B\Delta) \]

求偏導,可得到

\[\Delta = (B^T W_{x_0} B)^{-1} (B^T W_{x_0} Y) \]

那么,估計值

\[\begin{aligned} \hat{f(x_0)} &= e(x_0) (B^T W_{x_0} B)^{-1} (B^T W_{x_0} Y) \\ & = \sum_i w_i (x_0) y_i \end{aligned} \]

其中,\(e(x_0) = \begin{pmatrix} 1, x_0, \cdots, x_0^d \end{pmatrix}\)。上述回歸方法稱之為LOWESS (LOcal Weighted regrESSion)。

2. Robust LOWESS

Robust LOWESS是Cleveland [1] 在LOWESS基礎上提出來的robust回歸方法,能避免outlier對回歸的影響。在計算完估計值后,計算殘差:

\[e_i = y_i - \hat{f(x_i)} \]

根據殘差計算robustnest weight:

\[\delta_i = B(e_i/6s) \]

其中,\(s\)為殘差絕對值序列\(|e_i|\)d的中位值(median),\(B\)函數為bisquare函數:

\[B(u) = \left \{ { \matrix { {(1-u^2)^2 } & {for \quad 0 \le u < 1} \cr { 0 } & {for \quad u \ge 1} \cr } } \right. \]

然后,用robustness weight乘以kernel weight作為\(W_{x_0}\)的新weight。如此,便剔除了殘差較大的異常點對於回歸的影響。這里有Python版實現。

3. 參考資料

[1] Trevor Hastie, Robert Tibshirani, Jerome H. Friedman. The elements of statistical learning. Springer, Berlin: Springer series in statistics, 2009.
[2] Cleveland, William S. "Robust locally weighted regression and smoothing scatterplots." Journal of the American statistical association 74.368 (1979): 829-836.
[3] peterf, The Local Polynomial Regression Estimator.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM