You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a package for local weighted linear regression.
The way local weighted lienar regression predicts a value $y_{\text{pred},i}$ for an input $x_{\text{test},i}$ is by finding the $k$ nearest neighbors of $x_{\text{test},i}$ in the training set $x_{\text{train}}$ and using these neighbors (along with their labels $y_{\text{train}}$) to fit a straight line locally.
The weights $w_{\text{train},j}$ implemented in this package are 'constant', 'inverse_distance', and 'inverse_distance_squared'. There is also the option to add custom weights. This minimization problem has an analytical solution $\boldsymbol{\theta}=(\textbf{X}^T\textbf{WX})^{-1}(\textbf{X}^T\textbf{WY})$, with $\textbf{X}$ being the matrix of features, $\textbf{W}$ a diagonal matrix of the weights, and $\textbf{Y}$ the matrix of outcomes.
Installation
pip install lwlr
Dependencies
Python >= 3.6
sklearn
numpy
Usage
The model can be used with a few simple lines of code:
from lwlr import LWLR
model = LWLR(weight_type='inverse_distance')
y_pred = model.predict(x_test, x_train, y_train, nn=5)
A detailed example is found in the usage_example notebook.
About
Python package for local weighted linear regression.