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

detach error #173

Open
MoroderMind opened this issue Apr 18, 2024 · 1 comment
Open

detach error #173

MoroderMind opened this issue Apr 18, 2024 · 1 comment

Comments

@MoroderMind
Copy link

MoroderMind commented Apr 18, 2024

Regarding this file
https://github.com/rasbt/machine-learning-book/blob/main/ch12/ch12_part2.ipynb
At topic (Model training via the torch.nn and torch.optim modules)

---CODE BELOW--
1 y_pred = model(X_test_norm).detach().numpy()
2 fig = plt.figure(figsize=(13, 5))
3 ax = fig.add_subplot(1, 2, 1)
4 plt.plot(X_train_norm.detach().numpy(), y_train.detach().numpy(), 'o', markersize=10)
5 plt.plot(X_test_norm.detach().numpy(), y_pred.detach().numpy(), '--', lw=3)

--ERROR--
Line 5 y_pred.detach().numpy() should just be y_pred, since we already detached and converted to to numpy array.

@rasbt
Copy link
Owner

rasbt commented Apr 20, 2024

Thanks for the note. What you are describing sounds correct. I remember changing this though because some readers had issues otherwise; maybe it was OS or PyTorch version related. Have to look into that again. Thanks for reporting though!

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

2 participants