Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Figure 4-8 #136

Open
momodz16 opened this issue Jun 5, 2024 · 0 comments
Open

[QUESTION] Figure 4-8 #136

momodz16 opened this issue Jun 5, 2024 · 0 comments

Comments

@momodz16
Copy link

momodz16 commented Jun 5, 2024

def plot_gradient_descent(theta, eta):
m = len(X_b)

n_epochs = 1000
n_shown = 20
theta_path = []
for epoch in range(n_epochs):
    if epoch < n_shown:
        y_predict = X_new_b @ theta
        color = mpl.colors.rgb2hex(plt.cm.OrRd(epoch / n_shown + 0.15))
        plt.plot(X_new, y_predict, linestyle="solid", color=color)
    gradients = 2 / m * X_b.T @ (X_b @ theta - y)
    theta = theta - eta * gradients
    theta_path.append(theta)

#PUT THIS LINE AFTER THE LOOP TO GET BETTER Figure 4-8. THE DATASET IS NOW MORE VISIBLE
plt.plot(X, y, "b.")

plt.xlabel("$x_1$")
plt.axis([0, 2, 0, 15])
plt.grid()
plt.title(fr"$\eta = {eta}$")
return theta_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant