Implementation of Locally Weighted Linear Regression
LOESS or LOWESS are non-parametric regression methods that combine multiple regression models in a k-nearest-neighbor-based meta-model. LOESS combines much of the simplicity of linear least squares regression with the flexibility of nonlinear regression. It does this by fitting simple models to localized subsets of the data to build up a function that describes the variation in the data, point by point.
- This algorithm is used for making predictions when there exists a non-linear relationship between the features.
- Locally weighted linear regression is a supervised learning algorithm.
- It a non-parametric algorithm.
- doneThere exists No training phase. All the work is done during the testing phase/while making predictions.
Suppose we want to evaluate the hypothesis function h at a certain query point x. For linear regression we would do the following:
For locally weighted linear regression we will instead do the following:
where w(i) is a is a non-negative “weight” associated with training point x(i). A higher “preference” is given to the points in the training set lying in the vicinity of x than the points lying far away from x. so For x(i) lying closer to the query point x, the value of w(i) is large, while for x(i) lying far away from x the value of w(i) is small.
w(i) can be chosen as –
Directly using closed Form solution to find parameters-
Code: Importing Libraries :
Attention reader! Don’t stop learning now. Get hold of all the important Machine Learning Concepts with the Machine Learning Foundation Course at a student-friendly price and become industry ready.
Code: Loading Data :
Code: Function to calculate weight matrix :
Code: Making Predictions:
Code: Visualise Predictions :