3-1线性回归预测房价
个人学习记录,仅供自己复习使用
torch.normal(mean, std, *,size)
mean (float) – the mean for all distributions
std (float) – the standard deviation for all distributions
size (int…) – a sequence of integers defining the shape of the output tensor.
* - 命名关键字参数这里表示后面的参数可选且一定要写成size=x的格式
reshape(...面,行,列)
-1表示不做要求
torch.tensor([x,y])
创建指定向量
torch.matmul(x,y)
张量形状为xyz*w、
张量[x],表示第一维
张量[x,y],表示第一维度,第二维度,即体,面
张量[x,y,z],表示第三维度,即体,面,行
python里np.array 的shape (n,)是一维数组,里面有n个元素
shape(n,1)是二维数组,n行1列
matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None, plotnonfinite=False, data=None, **kwargs)
课程里pyplot写成plt,第一个参数x轴,第二个参数y轴,第三个参数输入数字简单理解为点的大小
python形参:可变形参,命名关键字参数,位置参数,关键字参数,默认参数
detach().numpy()把torch张量变成numpy张量
features[:,1]
我们以,逗号为分界线,之前1是第二行,因为数组中索引是从0开始的,那么:代表什么呢?
代表取这个一行所有的值,代表all
len(张量)
此函数只获得一个维度的个数,并非所有元素个数。维度从左开始计数`
#torch.tensor的一个object
name_tensor.shape
#获取张量的形状
range(start, stop, step)
官方解释:The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times == in for loops ==
list()
强制类型转换
shuffle()是不能直接访问的,需哟啊导入random模块,然后通过random静态对象调用该方法
for()循环不要忘记加“:”号
torch.zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)
常用参数:
lr:学习率
sgd:stochatic gradient descent随机梯度下降
torch.no_grad()
Disabling gradient calculation is useful for inference, when you are sure that you will not call Tensor.backward(). It will reduce memory consumption for computations that would otherwise have requires_grad=True.
l.sum().backward()