Classification accuracy is the fraction of predictions that match their true labels. It gives a direct, practical measure of how often a trained classifier gets an example right. section 2.3.3
For binary classification, convert predicted probabilities into labels with a cutoff: probabilities below 0.5 become 0, and probabilities at or above 0.5 become 1. Compare those labels with the actual labels, count matches, and average the results across test batches. section 2.3.3
Fashion MNIST classification
An ankle-boot classifier reaches 87.84% accuracy on the test set. For ten-category clothing classification, choose the class with torch.argmax, compare it with the true label, and obtain an accuracy of 0.8819665605095541. 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}")
Follow the complete PyTorch calculation: load test batches, reshape images and labels, threshold predictions, compare tensors, average matches, and print accuracy. section 2.3.3































