删除重复数据集

main
get 10 months ago
parent 3eb184033a
commit 6be679912b

@ -26,4 +26,10 @@ print(result)
print((result['eval'][-3:].sum()-result['pred'][-3:].sum())/result['eval'].sum())
import numpy as np
X_eval = np.array([
[22.3,16.19,23,1,0],
[23.69,14.5,23,0,0],
[23.69,14,23,0,0]])
print(model.predict(X_eval))

@ -118,48 +118,48 @@ eval_y = torch.from_numpy(eval_y).to(device).type(torch.float32)
model = LSTM_Regression(DAYS_FOR_TRAIN, 32, output_size=3, num_layers=2).to(device) # 导入模型并设置模型的参数输入输出层、隐藏层等
loss_function = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.005, betas=(0.9, 0.999), eps=1e-08, weight_decay=0)
min_loss = 1
for i in range(2500):
model.train()
out = model(train_x)
loss = loss_function(out, train_y)
loss.backward()
optimizer.step()
optimizer.zero_grad()
model.eval()
with torch.no_grad():
pred = model(eval_x)
eval_loss = loss_function(pred,eval_y)
if eval_loss <= min_loss:
min_loss = eval_loss
best_param = model.state_dict()
if (i+1) % 100 == 0:
print(f'epoch {i+1}/1500 loss:{round(loss.item(),5)}')
# 保存模型
torch.save(best_param,'best_dy3.pth')
# loss_function = nn.MSELoss()
# optimizer = torch.optim.Adam(model.parameters(), lr=0.005, betas=(0.9, 0.999), eps=1e-08, weight_decay=0)
#
# min_loss = 1
# for i in range(2500):
# model.train()
# out = model(train_x)
# loss = loss_function(out, train_y)
# loss.backward()
# optimizer.step()
# optimizer.zero_grad()
#
# model.eval()
# with torch.no_grad():
# pred = model(eval_x)
# eval_loss = loss_function(pred,eval_y)
# if eval_loss <= min_loss:
# min_loss = eval_loss
# best_param = model.state_dict()
#
# if (i+1) % 100 == 0:
# print(f'epoch {i+1}/1500 loss:{round(loss.item(),5)}')
#
# # 保存模型
# torch.save(best_param,'best_dy3.pth')
# for test
model = model.eval()
dataset_x = dataset_x.reshape(-1, 1, DAYS_FOR_TRAIN) # (seq_size, batch_size, feature_size)
dataset_x = torch.from_numpy(dataset_x).to(device).type(torch.float32)
pred_test = model(dataset_x)
# 模型输出 (seq_size, batch_size, output_size)
pred_test = pred_test.view(-1)
pred_test = np.concatenate((np.zeros(DAYS_FOR_TRAIN), pred_test.cpu().detach().numpy()))
plt.plot(pred_test.reshape(-1), 'r', label='prediction')
plt.plot(dataset_y.reshape(-1), 'b', label='real')
plt.plot((train_size*3, train_size*3), (0, 1), 'g--') # 分割线 左边是训练数据 右边是测试数据的输出
plt.legend(loc='best')
plt.show()
# model = model.eval()
#
# dataset_x = dataset_x.reshape(-1, 1, DAYS_FOR_TRAIN) # (seq_size, batch_size, feature_size)
# dataset_x = torch.from_numpy(dataset_x).to(device).type(torch.float32)
#
# pred_test = model(dataset_x)
# # 模型输出 (seq_size, batch_size, output_size)
# pred_test = pred_test.view(-1)
# pred_test = np.concatenate((np.zeros(DAYS_FOR_TRAIN), pred_test.cpu().detach().numpy()))
#
# plt.plot(pred_test.reshape(-1), 'r', label='prediction')
# plt.plot(dataset_y.reshape(-1), 'b', label='real')
# plt.plot((train_size*3, train_size*3), (0, 1), 'g--') # 分割线 左边是训练数据 右边是测试数据的输出
# plt.legend(loc='best')
# plt.show()
# 创建测试集

Loading…
Cancel
Save