if epoch % 50 == 0: print("epoch:", epoch, "loss:", loss.item())
# print(regression_model) ''' torch.from_numpy(x): put the data formation from numpy into tensor data.numpy(): get the results require_grad: use gradient descent to update the weights ''' # predict = regression_model(torch.from_numpy(x).requires_grad_()).data.numpy() # 通过训练好的模型预测结果 predict = regression_model(torch.from_numpy(x).requires_grad_(False)).detach().numpy() # 通过训练好的模型预测结果
# another way # tensor_x = torch.from_numpy(x).float().to(device) # tensor_x.requires_grad_(True) # predict = regression_model(tensor_x).detach().numpy()