Professional Documents
Culture Documents
Exp-12 - Jupyter Notebook
Exp-12 - Jupyter Notebook
In [53]:
import numpy as np
In [54]:
n = 10
X = np.linspace(-3, 3, num=n)
y = np.abs(X ** 3 - 1)
X += np.random.normal(scale=.1, size=n)
In [55]:
In [56]:
theta = np.linalg.pinv(xw @ X) @ xw @ y
return theta @ x
In [57]:
tau = 0.1
domain = np.linspace(-3, 3, num=300)
prediction = [local_weighted_regression(x0, X, y, tau) for x0 in domain]
localhost:8888/notebooks/Exp-12.ipynb 1/2
5/23/22, 8:12 PM Exp-12 - Jupyter Notebook
In [58]:
plt.scatter(X, y, alpha=.3)
plt.plot(domain, prediction, color='red')
Out[58]:
[<matplotlib.lines.Line2D at 0x149423c0070>]
In [ ]:
localhost:8888/notebooks/Exp-12.ipynb 2/2