var.to_csv(path+'/test_rmse.csv',index = False,header = False) #var = pd.DataFrame(alpha1) #var.to_csv(path+'/alpha.csv',index = False, header = False) #print('min_rmse:%r'%(np.min(test_rmse)), # 'min_mae:%r'%(np.min(test_mae)), # 'max_acc:%r'%(np.max(test_acc))) index = test_rmse.index(np.min(test_rmse)) #test_mae.index(np.min(test_mae)) #test_acc.index(np.max(test_acc)) test_result = test_pred[index] var = pd.DataFrame(test_result) var.to_csv(path+'/test_result.csv',index = False,header = False) plot_result(test_result,test_label1,path) plot_error(train_rmse,train_loss,test_rmse,test_acc,test_mae,path) fig1 = plt.figure(figsize=(7,3)) ax1 = fig1.add_subplot(1,1,1) plt.plot(np.sum(alpha1,0)) plt.savefig(path+'/alpha.jpg',dpi=500) plt.show() plt.imshow(np.mat(np.sum(alpha1,0))) plt.savefig(path+'/alpha11.jpg',dpi=500) plt.show() print('min_rmse:%r'%(np.min(test_rmse)), 'min_mae:%r'%(test_mae[index]), 'max_acc:%r'%(test_acc[index]),
validation_label = target_cpu * max_value validation_pred.append(pred_cpu * max_value) # mae = np.mean(np.absolute(pred_unnormalized - target_unnormalized)) # validation_maes.append(mae) out = None val_input = val_input.to(device="cpu") val_target = val_target.to(device="cpu") print('epoch' + str(epoch)) print("Training loss: {}".format(training_losses[-1])) print("Training rmse: {}".format(training_rmses[-1])) print("Validation loss: {}".format(validation_losses[-1])) print("Validation rmse: {}".format(validation_rmse[-1])) print("Validation acc: {}".format(validation_acc[-1])) if (epoch % 1000 == 0): torch.save(net, './torchimage/model_epoch' + str(epoch) + '.pkl') index = validation_rmse.index( np.min(validation_rmse)) # 找出testrmse中最小的那个epoch test_result = validation_pred[index] var = pd.DataFrame(test_result) var.to_csv('./torchimage' + '/test_result_epoch' + str(index) + '.csv', index=False, header=False) print(validation_label.shape) print(test_result.shape) plot_result_3ave(test_result, validation_label, './torchimage/') # shape为[testbatch*prelen, num_nodes] plot_error(training_rmses, training_losses, validation_rmse, validation_acc, validation_maes, './torchimage/')