# How to calculate sensitivity, precision, recall and F1 score of my binary dataset with output labels 0 and 1

How can I calculate sensitivity, precision, recall and F1 score of my binary dataset. The output values are 0 and 1.

``````model = Net()
loss_func = nn.NLLLoss()
criterion = nn.CrossEntropyLoss()

epochs = 2
loss_list = []

model.train()
for epoch in range(epochs):
total_loss = []
for i, data in enumerate(train_ldr, 0):
# get the inputs; data is a list of [inputs, labels]
X_train,Y_train = data.values()
X_train = X_train.unsqueeze(0)
X_train = X_train.unsqueeze(1)

# Forward pass
output = model(X_train)
# Calculating loss
loss = criterion(output, Y_train)

# Backward pass
loss.backward()
# Optimize the weights
optimizer.step()

total_loss.append(loss.item())
loss_list.append(sum(total_loss)/len(total_loss))
print('Training [{:.0f}%]\tLoss: {:.4f}'.format(
100. * (epoch + 1) / epochs, loss_list[-1]))

model.eval()
criterion = nn.CrossEntropyLoss()

correct = 0
for i, data in enumerate(test_ldr, 0):

X_test,Y_test = data.values()
X_test = X_test.unsqueeze(0)
X_test = X_test.unsqueeze(1)
output = model(X_test)

pred = output.argmax(dim=1, keepdim=True)
correct += pred.eq(Y_test.view_as(pred)).sum().item()

loss = criterion(output, Y_test)
total_loss.append(loss.item())

print('Performance on test data:\n\tLoss: {:.4f}\n\tAccuracy: {:.1f}%'.format(
sum(total_loss) / len(total_loss),
correct / len(test_ldr) * 100)
)
``````

In this case, I recommend you use the scikit-learn package for computing some evaluation metric.

It would be great unless you have to accelerate the evaluation process due to the large data.