Accuracy is the fraction of classification predictions that match the true labels. It provides a straightforward way to evaluate predictions on a test dataset. section 2.3.3 section 2.4.2
Calculate accuracy by turning model outputs into predicted labels, then comparing them with the true labels:
- For binary classification, convert probabilities below 0.5 to 0 and probabilities at or above 0.5 to 1. section 2.3.3
- For multicategory classification, choose the class with the highest output value. section 2.4.2
- Compare predicted and true labels, then average the matches. section 2.3.3 section 2.4.2
Fashion MNIST classification
A binary image classifier distinguishes ankle boots from T-shirts and reports 87.84% accuracy on the test set. A multicategory classifier evaluates ten clothing labels and reports accuracy of about 0.882. section 2.3.3 section 2.4.2
Listing 2.7 Calculating the accuracy of the predictions
import numpy as np
results=[]
for imgs,labels in binary_test_loader: #1
imgs=imgs.reshape(-1,28*28).to(device)
labels=(labels/9).reshape(-1,1).to(device)
preds=binary_model(imgs)
pred10=torch.where(preds>0.5,1,0) #2
correct=(pred10==labels) #3
results.append(correct.detach().cpu()\
.numpy().mean()) #4
accuracy=np.array(results).mean() #5
print(f"the accuracy of the predictions is {accuracy}")
See the PyTorch listing that thresholds binary predictions, compares them with labels, and calculates accuracy. section 2.3.3

































