The values of the accuracy, precision, and recall are close and I’m a little worried about these values. My question is these values are reliable? like the below:
Test Loss: 0.389 | Test accuracy: 0.919 | Test precision: 0.741 | Train recall: 0.742
Test F1: 0.741
I calculated these values as :
def train(model, iterator, optimizer, criterion, clip):
model.train()

epoch_loss = 0
epoch_acc = 0 
epoch_precision = 0 
epoch_recall = 0 

for i, batch in enumerate(iterator):
    
    src = batch.src
    trg = batch.trg
    
    optimizer.zero_grad()
    
    output, attention = model(src, trg[:,:-1])

    
    output = output.contiguous().view(-1, output.shape[-1])
    trg = trg[:,1:].contiguous().view(-1)       

    loss = criterion(output, trg)
    aa = acc(output, trg)
    precision = get_precision(output, trg)
    recall = get_recall(output, trg)
    
    loss.backward()
    
    torch.nn.utils.clip_grad_norm_(model.parameters(), clip)
    
    optimizer.step()
    
    epoch_loss += loss.item()
    epoch_acc +=  aa  
    epoch_precision += precision
    epoch_recall += recall 
    
return epoch_loss / len(iterator), epoch_acc / len(iterator), epoch_precision / len(iterator), epoch_recall / len(iterator)

N_EPOCHS = 100
CLIP = 1
best_valid_loss = float(‘inf’)
for epoch in range(N_EPOCHS):
start_time = time.time()

train_loss, train_acc, train_prce, train_recall  = train(model, train_iterator, optimizer, criterion, CLIP)
trainf1score = train_prce * train_recall * 2 / (train_prce + train_recall + 1e-20)
  
end_time = time.time()

epoch_mins, epoch_secs = epoch_time(start_time, end_time)

if valid_loss < best_valid_loss:
    best_valid_loss = valid_loss
    torch.save(model.state_dict(), 'tut5-model.pt')

print(f'Epoch: {epoch+1:02} | Time: {epoch_mins}m {epoch_secs}s')
print(f'\tTrain Loss: {train_loss:.3f} | Train accuracy: {train_acc:.3f} | Train precision: {train_prce:.3f} | Train recall: {train_prce:.3f}')
print(f'\tTrain F1: {trainf1score:.3f}')