Skip to content

Commit

Permalink
fix: error function is generated
Browse files Browse the repository at this point in the history
Signed-off-by: Arkadip <[email protected]>
  • Loading branch information
darkmatter18 committed Feb 26, 2020
1 parent 8489e13 commit 596ce8e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def fit(self, trainloader, validationloader, criterion, optimizer, epochs, val_p

ps = self.forward(data)
testloss += self.criterion(ps, target).item()

testloss = testloss / len(validationloader)
trainloss = trainloss / len(trainloader)

Expand Down Expand Up @@ -191,9 +192,9 @@ def save_summary(self, path):

def errors(self, testloader):
self.eval()
mae = 0
mse = 0
mape = 0
mae = torch.Tensor([0])
rmse = torch.Tensor([0])
mape = torch.Tensor([0])

for f, l in testloader:
f = f.type(torch.FloatTensor)
Expand All @@ -202,14 +203,18 @@ def errors(self, testloader):
if self.cuda:
f, l = f.cuda(), l.cuda()

mae += F.l1_loss(self.forward(f), l).item()
mse += torch.sqrt(F.mse_loss(self.forward(f), l)).item()
mape += torch.mean(torch.abs((l - self.forward(f)) / l)).item()

mae += F.l1_loss(self.forward(f), l)
rmse += F.mse_loss(self.forward(f), l)
mape += torch.mean(torch.abs((l - self.forward(f)) / l))

# Mean in values
mae /= len(testloader)
mse /= len(testloader)
rmse /= len(testloader)
mape /= len(testloader)

print("MAE: ", mae)
print("MSE: ", mse)
print("MAPE: ", mape)

# square rooting the end result
rmse = torch.sqrt(rmse)

print(f"MAE: {round(mae.item(), 4)}")
print(f"RMSE: {round(rmse.item(), 4)}")
print(f"MAPE: {round(mape.item() * 100, 4)} %")

0 comments on commit 596ce8e

Please sign in to comment.