def load_data(file_name): df = pd.read_csv('data/new_data/' + file_name, encoding='gbk') columns = df.columns df.fillna(df.mean(), inplace=True) return df class MyDataset(Dataset): def __init__(self, data): self.data = data def __getitem__(self, item): return self.data[item] def __len__(self): return len(self.data) def nn_seq_us(B): print('data processing...') dataset = load_data() # split train = dataset[:int(len(dataset) * 0.6)] val = dataset[int(len(dataset) * 0.6):int(len(dataset) * 0.8)] test = dataset[int(len(dataset) * 0.8):len(dataset)] m, n = np.max(train[train.columns[1]]), np.min(train[train.columns[1]]) def process(data, batch_size): load = data[data.columns[1]] load = load.tolist() data = data.values.tolist() load = (load - n) / (m - n) seq = [] for i in range(len(data) - 24): train_seq = [] train_label = [] for j in range(i, i + 24): x = [load[j]] train_seq.append(x) # for c in range(2, 8): # train_seq.append(data[i + 24][c]) train_label.append(load[i + 24]) train_seq = torch.FloatTensor(train_seq) train_label = torch.FloatTensor(train_label).view(-1) seq.append((train_seq, train_label)) # print(seq[-1]) seq = MyDataset(seq) seq = DataLoader(dataset=seq, batch_size=batch_size, shuffle=False, num_workers=0, drop_last=True) return seq Dtr = process(train, B) Val = process(val, B) Dte = process(test, B) return Dtr, Val, Dte, m, n这是关于什么的代码
时间: 2024-04-28 10:22:56 浏览: 132
这是一个关于神经网络序列预测的代码,它将数据集加载并进行预处理,然后将其分为训练、验证和测试集。代码中的 load_data 函数用于加载数据文件,MyDataset 类用于创建数据集对象,nn_seq_us 函数则用于对数据进行预处理并将其转换为 PyTorch 数据加载器对象。最后,该函数返回训练、验证和测试数据集对象,以及数据的最大值和最小值。
阅读全文