KNeighborsHatMatrix#
- class skfda.misc.hat_matrix.KNeighborsHatMatrix(*, n_neighbors=None, kernel=<function uniform>)[source]#
K-nearest neighbour kernel method.
Creates the matrix \(\hat{H}\), used in the kernel smoothing and kernel regression algorithms, as explained below.
\[\hat{H}_{i,j} = \frac{K\left(\frac{d(x_j-x_i')}{h_i}\right)} {\sum_{k=1}^{n}K\left(\frac{d(x_k-x_i')}{h_{i}}\right)}\]For smoothing, \(\{x_1, ..., x_n\}\) are the points with known value and \(\{x_1', ..., x_m'\}\) are the points for which it is desired to estimate the smoothed value. The distance \(d\) is the absolute value.
For regression, \(\{x_1, ..., x_n\}\) are the functional data and \(\{x_1', ..., x_m'\}\) are the functions for which it is desired to estimate the scalar value. Here, \(d\) is some functional distance.
In both cases, \(K(\cdot)\) is a kernel function and \(h_{i}\) is calculated as the distance from \(x_i'\) to its
n_neighbors
-th nearest neighbor in \(\{x_1, ..., x_n\}\) [1].Used with the uniform kernel, it takes the average of the closest
n_neighbors
points to a given point.- Parameters:
n_neighbors (int | None) – Number of nearest neighbours. By default it takes the 5% closest elements.
kernel (Callable[[NDArrayFloat], NDArrayFloat]) – Kernel function. By default a uniform kernel to perform a ‘usual’ k nearest neighbours estimation.
References
Methods
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
set_params
(**params)Set the parameters of this estimator.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)#
Get parameters for this estimator.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance