【无标题】3_1线性回归,仅供自己复习使用。很乱

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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值