Noob: what are these lines doing in calculating epoch loss and accuracy?

    epoch_loss = (epoch_loss / len(data_loader)).item()
    epoch_acc = (epoch_acc / len(data_loader.dataset)) * 100

from Titanic-Machine-Learning-and-Deep-Learning/deep-learning.ipynb at main · windsuzu/Titanic-Machine-Learning-and-Deep-Learning · GitHub

data_loader is a class that conveniently loads data in batches so how is that taking .item() from the math done inside the (())?

Hey,
.item() returns the value of a (single valued) tensor as a python object.

In the first line, it’s just taking the average of the losses from all the batches in a single epoch to get the epoch_loss.

Similarly, epoch_acc is the average accuracy in the second line.

Thanks @srishti-git1110 !