A local polynomial of degree p fits a weighted polynomial around each point x, with tricube weights K((xi − x)/h), and keeps its value at x. The result is a linear smoother r̂(x) = Σ ℓi(x)Yi: the middle panel shows the weights ℓi(x), the effective kernel, at a point you choose. The effective degrees of freedom are ν = tr L = Σ ℓi(xi), and the leave-one-out score needs one fit: (Yi − r̂(xi))/(1 − Lii). p = 0 is the Nadaraya–Watson kernel estimator; p = 1 removes its boundary and design bias.
Tricube kernel K(u) = (70/81)(1 − |u|3)3 on [−1, 1]. The bandwidth runs over the grids of the course code (log-spaced; 10 to 150 in steps of 1 for LIDAR). The fit is computed at the data points; where a window holds too few points for degree p the fit is undefined and the score infinite. GCV replaces each Lii by ν/n.
code/ch05_nonparametric_regression.py (locpoly_matrix, ll_matrix, nw_matrix, loo_cv, gcv, select_h).