# Kernel smoother

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Kernel_smoother
> Markdown URL: https://mediated.wiki/source/Kernel_smoother.md
> Source: https://en.wikipedia.org/wiki/Kernel_smoother
> Source revision: 1353399338
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Statistical technique}}
A '''kernel smoother''' is a [statistical](/source/statistics) technique to estimate a real valued [function](/source/function_(mathematics)) <math>f: \mathbb{R}^p \to \mathbb{R}</math> as the [weighted average](/source/weighted_average) of neighboring observed data. The weight is defined by the ''[kernel](/source/Kernel_(statistics))'', such that closer points are given higher weights. The estimated function is smooth, and the level of smoothness is set by a single parameter.
Kernel smoothing is a type of [weighted moving average](/source/weighted_moving_average).

==Definitions==

Let <math>K_{h_\lambda}(X_0 ,X)</math> be a kernel defined by

:<math>K_{h_\lambda}(X_0 ,X) = D\left( \frac{\left\| X-X_0 \right\|}{h_\lambda (X_0)} \right)</math>

where: 
* <math>X,X_0 \in \mathbb{R}^p</math>
* <math>\left\| \cdot  \right\|</math> is the [Euclidean norm](/source/Euclidean_norm)
* <math>h_\lambda (X_0)</math> is a parameter (kernel radius)
* ''D''(''t'') is typically a positive real valued function, whose value is decreasing (or not increasing) for the increasing distance between the ''X'' and ''X''<sub>0</sub>.

Popular [kernels](/source/Kernel_(statistics)) used for smoothing include parabolic (Epanechnikov), tricube, and [Gaussian](/source/Gaussian_function) kernels.

Let <math>Y(X):\mathbb{R}^p \to \mathbb{R}</math> be a [continuous function](/source/continuous_function) of ''X''.  For each <math>X_0 \in \mathbb{R}^p</math>, the Nadaraya-Watson kernel-weighted average (smooth ''Y''(''X'') estimation) is defined by

:<math>\hat{Y}(X_{0})=\frac{\sum\limits_{i=1}^{N}{K_{h_{\lambda }}(X_{0},X_{i})Y(X_{i})}}{\sum\limits_{i=1}^{N}{K_{h_{\lambda }}(X_{0},X_{i})}}</math>

where: 
* ''N'' is the number of observed points
* ''Y''(''X''<sub>''i''</sub>) are the observations at ''X''<sub>''i''</sub> points.

In the following sections, we describe some particular cases of kernel smoothers.

==Gaussian kernel smoother==

thumbnail|Gaussian kernel regression smoother example.

The [Gaussian kernel](/source/radial_basis_function_kernel) is one of the most widely used kernels, and is expressed with the equation below.

:<math> K(x^*,x_i)=\exp\left(-\frac{(x^*-x_i)^2}{2b^2}\right) </math>

Here, b is the [length scale](/source/length_scale) for the input space.

==Nearest neighbor smoother==
{{distinguish|Nearest neighbor interpolator}}

thumbnail|Nearest neighbor smoother example.

The [''k''-nearest neighbor algorithm](/source/k-nearest_neighbor_algorithm) can be used for defining a '''''k''-nearest neighbor smoother''' as follows. For each point ''X''<sub>0</sub>, take ''m'' nearest neighbors and estimate the value of ''Y''(''X''<sub>0</sub>) by averaging the values of these neighbors.

Formally, <math>h_m (X_0)=\left\| X_0 - X_{[m]} \right\|</math>, where <math>X_{[m]}</math> is the ''m''th closest to ''X''<sub>0</sub> neighbor, and

: <math>D(t)= \begin{cases}
1/m & \text{if } |t| \le 1 \\
0 & \text{otherwise}
\end{cases}
</math>

In this example, ''X'' is one-dimensional. For each X<sub>0</sub>, the <math>\hat{Y}(X_0)</math> is an average value of 16 closest to ''X''<sub>0</sub> points (denoted by red).

==Kernel average smoother==
{{main|Weighted moving average}}

thumbnail|Kernel average smoother example.

The idea of the kernel average smoother is the following. For each data point ''X''<sub>0</sub>, choose a constant distance size ''&lambda;'' (kernel radius, or window width for ''p''&nbsp;=&nbsp;1 dimension), and compute a weighted average for all data points that are closer than <math>\lambda </math> to ''X''<sub>0</sub> (the closer to ''X''<sub>0</sub> points get higher weights).

Formally, <math>h_\lambda (X_0)=\lambda = \text{constant},</math> and ''D''(''t'') is one of the popular kernels.

For each ''X''<sub>0</sub> the window width is constant, and the weight of each point in the window is schematically denoted by the yellow figure in the graph. It can be seen that the estimation is smooth, but the boundary points are biased. The reason for that is the non-equal number of points (from the right and from the left to the ''X''<sub>0</sub>) in the window, when the ''X''<sub>0</sub> is close enough to the boundary.

==Local regression==
{{main|Local regression}}

===Local linear regression===
In the two previous sections we assumed that the underlying Y(X) function is locally constant, therefore we were able to use the weighted average for the estimation. The idea of local linear regression is to fit locally a straight line (or a [hyperplane](/source/hyperplane) for higher dimensions), and not the constant (horizontal line). After fitting the line, the estimation  <math>\hat{Y}(X_{0})</math>  is provided by the value of this line at ''X''<sub>0</sub> point. By repeating this procedure for each ''X''<sub>0</sub>, one can get the estimation function <math>\hat{Y}(X)</math>.
Like in previous section, the window width is constant <math>h_\lambda (X_0)=\lambda = \text{constant}.</math>
Formally, the local linear regression is computed by solving a weighted least square problem.

thumbnail|299x299px|Local linear regression result

For one dimension (''p'' = 1):

<math>\begin{align}
  & \min_{\alpha (X_0),\beta (X_0)} \sum\limits_{i=1}^N {K_{h_{\lambda }}(X_0,X_i)\left( Y(X_i)-\alpha (X_0)-\beta (X_{0})X_i \right)^2} \\ 
 & \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\Downarrow  \\ 
 & \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\hat{Y}(X_{0})=\alpha (X_{0})+\beta (X_{0})X_{0} \\ 
\end{align}</math>

The closed form solution is given by:

: <math>\hat{Y}(X_0)=\left( 1,X_0 \right)\left( B^{T}W(X_0)B \right)^{-1}B^{T}W(X_0)y</math>

where:
* <math>y=\left( Y(X_1),\dots,Y(X_N) \right)^T</math>
* <math>W(X_0)= \operatorname{diag} \left( K_{h_{\lambda }}(X_0,X_i) \right)_{N\times N}</math> 
* <math>B^{T}=\left( \begin{matrix}
   1 & 1 & \dots & 1  \\
   X_{1} & X_{2} & \dots & X_{N}  \\
\end{matrix} \right)</math>
The resulting function is smooth, and the problem with the biased boundary points is reduced.

Local linear regression can be applied to any-dimensional space, though the question of what is a local neighborhood becomes more complicated. It is common to use k nearest training points to a test point to fit the local linear regression. This can lead to high variance of the fitted function. To bound the variance, the set of training points should contain the test point in their [convex hull](/source/convex_hull) (see Gupta et al. reference).

===Local polynomial regression===

Instead of fitting locally linear functions, one can fit polynomial functions.
For p=1, one should minimize:

:<math>\underset{\alpha (X_{0}),\beta _{j}(X_{0}),j=1,...,d}{\mathop{\min }}\,\sum\limits_{i=1}^{N}{K_{h_{\lambda }}(X_{0},X_{i})\left( Y(X_{i})-\alpha (X_{0})-\sum\limits_{j=1}^{d}{\beta _{j}(X_{0})X_{i}^{j}} \right)^{2}}</math>

with <math>\hat{Y}(X_{0})=\alpha (X_{0})+\sum\limits_{j=1}^{d}{\beta _{j}(X_{0})X_{0}^{j}}</math>

In general case (p>1), one should minimize:

:<math>\begin{align}
  & \hat{\beta }(X_{0})=\underset{\beta (X_{0})}{\mathop{\arg \min }}\,\sum\limits_{i=1}^{N}{K_{h_{\lambda }}(X_{0},X_{i})\left( Y(X_{i})-b(X_{i})^{T}\beta (X_{0}) \right)}^{2} \\ 
 & b(X)=\left( \begin{matrix}
   1, & X_{1}, & X_{2},... & X_{1}^{2}, & X_{2}^{2},... & X_{1}X_{2}\,\,\,...  \\
\end{matrix} \right) \\ 
 & \hat{Y}(X_{0})=b(X_{0})^{T}\hat{\beta }(X_{0}) \\ 
\end{align}</math>

==See also==
*[Savitzky–Golay filter](/source/Savitzky%E2%80%93Golay_filter)
*[Kernel methods](/source/Kernel_methods)
*[Kernel density estimation](/source/Kernel_density_estimation)
*[Local regression](/source/Local_regression)
*[Kernel regression](/source/Kernel_regression)

==References==

* Li, Q. and J.S. Racine. ''Nonparametric Econometrics: Theory and Practice''. Princeton University Press, 2007, {{ISBN|0-691-12161-3}}.
* T. Hastie, R. Tibshirani and J. Friedman, ''The Elements of Statistical Learning'', Chapter 6, Springer, 2001. {{ISBN|0-387-95284-5}} ([https://web.stanford.edu/~hastie/ElemStatLearn/ companion book site]).
* M. Gupta, E. Garcia and E. Chin, [http://www.mayagupta.org/publications/GuptaGarciaChinTIP2008.pdf "Adaptive Local Linear Regression with Application to Printer Color Management,"] IEEE Trans. Image Processing 2008.

Category:Nonparametric statistics

---
Adapted from the Wikipedia article [Kernel smoother](https://en.wikipedia.org/wiki/Kernel_smoother) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Kernel_smoother?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
