IniziaInizia gratis

Analyzing metrics per class

While aggregated metrics are useful indicators of the model's performance, it is often informative to look at the metrics per class. This could reveal classes for which the model underperforms.

In this exercise, you will run the evaluation loop again to get our cloud classifier's precision, but this time per-class. Then, you will map these score to the class names to interpret them. As usual, Precision has already been imported for you. Good luck!

Questo esercizio fa parte del corso

Intermediate Deep Learning with PyTorch

Visualizza il corso

Istruzioni dell'esercizio

  • Define a precision metric appropriate for per-class results.
  • Calculate the precision per class by finishing the dict comprehension, iterating over the .items() of the .class_to_idx attribute of dataset_test.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Define precision metric
metric_precision = Precision(
    ____, ____, ____
)

net.eval()
with torch.no_grad():
    for images, labels in dataloader_test:
        outputs = net(images)
        _, preds = torch.max(outputs, 1)
        metric_precision(preds, labels)
precision = metric_precision.compute()

# Get precision per class
precision_per_class = {
    k: ____[____].____
    for k, v 
    in ____
}
print(precision_per_class)
Modifica ed esegui il codice