import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

x = np.array([1,1.2, 2, 3, 4, 5, 6, 7, 8, 9, 10])  # Feature
y = np.array([1,2.3, 2, 1.3, 3.75, 2.25, 5.5, 6.8, 8, 8.6, 10])  # Target

def LWR(xi,x,y):
    weights = norm.pdf(x,loc = xi, scale=0.5)
    return sum(weights*y)/sum(weights)

x_plot = np.linspace(0,10,200)
y_plot = [LWR(xi,x,y)for xi in x_plot]

plt.scatter(x,y,color='green',label='data')
plt.plot(x_plot,y_plot,color='red',label = 'LWR')
plt.xlabel('x');plt.ylabel('y');plt.title('LWR')
plt.legend();plt.grid(True);plt.show()