摘要: 首先要感谢CSDN中http://t.csdn.cn/XyT4e这篇文章(我接下来写的内容,也和这篇文章基本一样) 下面是我实际操作得到的结果: 我们看第一种情况的代码: import torch b = torch.arange(1, 61).reshape(3, 4, 5) idx1 = tor 阅读全文
posted @ 2023-06-14 00:29 啥都不会的灰太狼 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 在这里先把代码放上来 import torch import time import numpy as np import torchvision from torch.utils import data from torchvision import transforms from d2l imp 阅读全文
posted @ 2023-06-12 23:04 啥都不会的灰太狼 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 从零开始实现的代码如下: import math import random #随机梯度下降 随机的权重 import time import numpy as np from d2l import torch as d2l #实现过的函数写在d2l包中 ''' 加这两句是为了能画出散点图,不然会报 阅读全文
posted @ 2023-06-11 12:05 啥都不会的灰太狼 阅读(37) 评论(0) 推荐(0) 编辑
摘要: #我们在这里画的是方程3*x**2 - 4*x 在x = 1处的切线#欠拟合:欠拟合指的是模型对训练数据的拟合度过低,误差值过大,自然泛化能力也不怎么好。 #泛化能力指模型对未知数据的拟合度 #过拟合:指模型对训练数据的拟合度较好,误差值较小,但是泛化能力并不好。 #对误差函数进行惩罚,从而提高模型 阅读全文
posted @ 2023-06-08 21:34 啥都不会的灰太狼 阅读(93) 评论(0) 推荐(0) 编辑
摘要: import torch #标量由只有一个元素的张量表示 ''' x = torch.tensor(3.0) y = torch.tensor(2.0) print(x + y) print(x * y) print(x / y) print(x ** y) ''' ''' 向量可以被视为标量值组成 阅读全文
posted @ 2023-06-03 17:21 啥都不会的灰太狼 阅读(16) 评论(0) 推荐(0) 编辑
摘要: 内容简介: 1.将数据写入.csv文件中 2.将数据从.csv文件中读出 3.利用插值法处理缺失的数据 4.将数据类型转化为torch张量类型 代码如下: import os os.makedirs(os.path.join('..', 'data'), exist_ok=True) data_fi 阅读全文
posted @ 2023-05-30 19:41 啥都不会的灰太狼 阅读(16) 评论(0) 推荐(0) 编辑
摘要: 震惊了!!!在python中, y = x + y;与 y += x;竟然有区别,(y += x相当于 y[:] = y + x)且看如下代码: import torch ''' x = torch.arange(12) print(x) #reshape可以改变张量的形状而不改变元素的数量和元素值 阅读全文
posted @ 2023-05-29 23:29 啥都不会的灰太狼 阅读(76) 评论(0) 推荐(0) 编辑
摘要: import numpy as np Time = np.array([1, 2, 4, 8, 16, 32, 64]) Temp = np.array([0, 1, 2, 3, 4, 5, 6]) import matplotlib.pyplot as plt plt.figure() plt.p 阅读全文
posted @ 2023-05-28 10:56 啥都不会的灰太狼 阅读(31) 评论(0) 推荐(0) 编辑
摘要: #岭回归 from sklearn import linear_model #参数alpha用于控制复杂度,alpha的值越接近于0,岭回归器表现越接近于普通最小二乘法的线性回归器 #因此,若想让异常值具有良好的健壮性,就要为alpha分配一个较大的值,这里我们用一个中等大小的值0.01 ridge 阅读全文
posted @ 2023-05-27 21:13 啥都不会的灰太狼 阅读(20) 评论(0) 推荐(0) 编辑
摘要: filename = "Ve.txt" x = [] y = [] with open(filename, 'r') as f: for line in f.readlines(): xt,yt = [float(i) for i in line.split(',')] x.append(xt) y 阅读全文
posted @ 2023-05-27 20:50 啥都不会的灰太狼 阅读(20) 评论(0) 推荐(0) 编辑