Linear Regression
1. Prepare dataset
numpy中的广播机制:https://www.cnblogs.com/jiaxin359/p/9021726.html
![](https://tva1.sinaimg.cn/large/007S8ZIlgy1gimpp55tiij30ym0u0qn3.jpg)
import torch
x_data = torch.Tensor([[1.0], [2.0], [3.0]]) # 3*1 Tensor
y_data = torch.Tensor([2.0], [4.0], [6.0]) # 3*1 Tensor
2. Design model using Class
-
用Module构造出来的对象,会在构造计算图的过程中自动backward。
-
Linear layers
![](https://tva1.sinaimg.cn/large/007S8ZIlgy1gimq7x46x7j30y30u0gqa.jpg)
-
建立可调用对象
参考文章:https://www.jianshu.com/p/a96e71ff7f07?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
def func(*args, **kwargs):
print(args) # 返回的是(1, 2, 4, 3)
print(kwargs) # 返回的是 {'x': 3, 'y': 5}
func(1, 2, 4, 3, x=3, y=5)
class Foobar: