代码拉取完成,页面将自动刷新
import torch
import numpy as np
import pandas as pd
def load_matrix(file_path):
return pd.read_csv(file_path, header=None).values.astype(float)
def load_data(file_path, len_train, len_val):
df = pd.read_csv(file_path, header=None).values.astype(float)
train = df[: len_train]
val = df[len_train: len_train + len_val]
test = df[len_train + len_val:]
return train, val, test
def data_transform(data, n_his, n_pred, day_slot, device):
n_day = len(data) // day_slot
n_route = data.shape[1]
n_slot = day_slot - n_his - n_pred + 1
x = np.zeros([n_day * n_slot, 1, n_his, n_route])
y = np.zeros([n_day * n_slot, n_route])
for i in range(n_day):
for j in range(n_slot):
t = i * n_slot + j
s = i * day_slot + j
e = s + n_his
x[t, :, :, :] = data[s:e].reshape(1, n_his, n_route)
y[t] = data[e + n_pred - 1]
return torch.Tensor(x).to(device), torch.Tensor(y).to(device)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。