用kNN作平均迴歸:
\[ \hat{f(x)} = Ave(y_i | x_i \in N_k(x)) \]
其中,\(N_k(x)\)爲距離點x最近k個點組成的鄰域集合(neighborhood set)。這種鄰域平均迴歸存在不少缺點:git
所以引入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}) \]github
\[ 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]}| \]spa
其中,\(x_{[k]}\)爲距離\(x_0\)第k近的點。如上圖,經kernel加權平滑後,迴歸擬合的曲線爲連續的了。可是,這種kernel迴歸一樣存在着邊界(boundary)問題,以下圖:blog
對於x序列的開始與結束區段的點,其左右鄰域是不對稱的,致使了平滑後的值偏大或偏小。所以,須要對權值作再修正,假定對\(x_0\)的估計值:_ci
\[ \hat{f(x_0)} = \sum_{j=0}^d \beta_j x_0^{j} \]element
定義目標函數:
\[ \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} \]get
\[ 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} \]it
\[ \Delta = \begin{pmatrix} \beta_0, \beta_1, \cdots, \beta_d \end{pmatrix}^T \]io
\[ 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)。
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版實現。
[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.