|
|
@ -71,15 +71,22 @@ def to_data(file_dir, excel):
|
|
|
|
train_x = train_x.reshape(-1, 1, DAYS_FOR_TRAIN)
|
|
|
|
train_x = train_x.reshape(-1, 1, DAYS_FOR_TRAIN)
|
|
|
|
train_y = train_y.reshape(-1, 1, 1)
|
|
|
|
train_y = train_y.reshape(-1, 1, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 使用GPU
|
|
|
|
|
|
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
|
|
|
|
train_x.to(device)
|
|
|
|
|
|
|
|
train_y.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
# 转为pytorch的tensor对象
|
|
|
|
# 转为pytorch的tensor对象
|
|
|
|
train_x = torch.from_numpy(train_x)
|
|
|
|
train_x = torch.from_numpy(train_x)
|
|
|
|
train_y = torch.from_numpy(train_y)
|
|
|
|
train_y = torch.from_numpy(train_y)
|
|
|
|
|
|
|
|
|
|
|
|
model = LSTM_Regression(DAYS_FOR_TRAIN, 32, output_size=1, num_layers=2) # 导入模型并设置模型的参数输入输出层、隐藏层等
|
|
|
|
model = LSTM_Regression(DAYS_FOR_TRAIN, 32, output_size=1, num_layers=2) # 导入模型并设置模型的参数输入输出层、隐藏层等
|
|
|
|
|
|
|
|
|
|
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
# 使用GPU
|
|
|
|
print("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
print("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
model.to(device)
|
|
|
|
model.to(device)
|
|
|
|
|
|
|
|
# train_x.to(device)
|
|
|
|
|
|
|
|
# train_y.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
train_loss = []
|
|
|
|
train_loss = []
|
|
|
|
loss_function = nn.MSELoss()
|
|
|
|
loss_function = nn.MSELoss()
|
|
|
@ -106,8 +113,11 @@ def to_data(file_dir, excel):
|
|
|
|
model = model.eval() # 转换成测试模式
|
|
|
|
model = model.eval() # 转换成测试模式
|
|
|
|
# model.load_state_dict(torch.load(os.path.join(model_save_dir,model_file))) # 读取参数
|
|
|
|
# model.load_state_dict(torch.load(os.path.join(model_save_dir,model_file))) # 读取参数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataset_x = dataset_x.reshape(-1, 1, DAYS_FOR_TRAIN) # (seq_size, batch_size, feature_size)
|
|
|
|
dataset_x = dataset_x.reshape(-1, 1, DAYS_FOR_TRAIN) # (seq_size, batch_size, feature_size)
|
|
|
|
dataset_x = torch.from_numpy(dataset_x)
|
|
|
|
dataset_x = torch.from_numpy(dataset_x)
|
|
|
|
|
|
|
|
dataset_x.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
pred_test = model(dataset_x) # 全量训练集
|
|
|
|
pred_test = model(dataset_x) # 全量训练集
|
|
|
|
# 模型输出 (seq_size, batch_size, output_size)
|
|
|
|
# 模型输出 (seq_size, batch_size, output_size)
|
|
|
|