Our final method combines advantages of parametric methods with non-parametric. The idea is to fit a regression model locally, weighting examples by the kernel K.
Locally Weighted Regression Algorithm
Note that we can do the same for classification, fitting a locally weighted logistic regression:
Locally Weighted Logistic Regression Algorithm
The difference between regular linear regression and locally weighted linear regression can be visualized as follows:
Linear regression uses the same parameters for all queries and all errors affect the learned linear prediction. Locally weighted regression learns a linear prediction that is only good locally, since far away errors do not weigh much in comparison to local ones.
Here’s a result of using good kernel width on our regression examples (1/32, 1/32 and 1/16 of x-axis width, respectively):