PyTorch入门学习:5-Linear Regression with PyTorch
Linear Regression with Pytorch
1 PyTorch Fashion
- Prepare dataset
- Design model using Class: inherit from nn.Module
- Construct loss and optimizer: using PyTorch API
- Training cycle (forward, backward, update)
2 Prepare Dataset

3 Design Model
确认权重和张量的shape,如图中z的shape为[3,1],x的shape为[4,1],则w的shape为[3,4],b的shape为[3,1]。
4 Training Cycle
1 | |
5 Exercize
5.1 Try different optimizer
- Adagrad
- Adam
- Adamax
- RMSprop
- ASGD
- LBFGS
- Rprop
- SGD
5.2 Read more example from official tutorial
PyTorch入门学习:5-Linear Regression with PyTorch
https://eleco.top/2026/02/24/learn-torch-5-Linear-Regression-with-PyTorch/